Takes a set of functions and returns another that is the composition of those $fns
.
The result of the first function is used as unique argument of the second one and the
result of this for the third function and so on...
It's usually used in combination with apply function.
- fns
- Functions to be composed.
Multiply 2 numbers and divide the previous result by two:
<?php
use function Lambdish\Phunctional\apply;
use function Lambdish\Phunctional\compose;
$multiplier = function ($a, $b) {
return $a * $b;
};
$byTwoDivider = function ($num) {
return $num / 2;
};
$calculator = compose($byTwoDivider, $multiplier);
apply($calculator, [20, 10]);
// => 100