bendamqui / fp
Functional programming utils.
v1.0
2020-03-24 22:46 UTC
Requires
- php: ^7.2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16
- phpunit/phpunit: ^8.5
This package is auto-updated.
Last update: 2025-02-25 15:24:37 UTC
README
composer require bendamqui/fp
Functions
pipe(\Closure ...$fns)(mixed $initialValue = null)
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
compose(\Closure ...$fns)(mixed $initialValue = null)
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