bendamqui / fp
函数式编程工具。
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: 2024-09-25 14:15:31 UTC
README
composer require bendamqui/fp
函数
pipe(\Closure ...$fns)(mixed $initialValue = null)
从左到右应用函数到初始值。
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)
从右到左应用函数到初始值。
function add($x) { return function($y) use ($x) { return $x + $y; }; } compose(add(1), add(2), add(3))(0); // => 6