dev-master
9999999-devFunction to compose functions
MIT
The Requires
- php >=5.6
The Development Requires
Wallogit.com
2017 © Pedro Peláez
Function to compose functions
Function to compose functions., (*1)
Function-composition is commonly used technique in functional programming.
You can combine any callable's to build another function., (*2)
This library only supports PHP 5.6 later.
If you use the other version, igorw/compose is useful., (*3)
Calling compose($f, $g, $h) with an argument $x is equal to $f($g($h($x))), (*4)
<?php
use function yuyat\compose;
$splitAsWords = function ($str) {
return \preg_split('/\s+/u', $str);
};
$camelizeWords = function ($words) {
return \array_map('ucfirst', $words);
};
$join = function ($words) {
return \join('', $words);
};
$lowerCamelize = compose('lcfirst', $join, $camelizeWords, $splitAsWords);
echo $lowerCamelize('foo bar baz'); // => "fooBarBaz"
This function also combines functions, but the arguments order is reversed.
Functions are applied in order of your reading., (*5)
Calling pipeline($f, $g, $h) with an argument $x is equal to $h($g($f($x))), (*6)
Yuya Takeyama, (*7)
Function to compose functions
MIT