composer require bendamqui/fp
Apply functions to initial value from left to right.
function add($x) {
return function($y) use ($x) {
return $x + $y;
};
}
pipe(add(1), add(2), add(4))(0); // => 7
Apply functions to initial value from right to left.
function add($x) {
return function($y) use ($x) {
return $x + $y;
};
}
compose(add(1), add(2), add(3))(0); // => 6