bendamqui / fp
Functional programming utils.
2.0
2025-08-18 20:01 UTC
Requires
- php: ^8.4
Requires (Dev)
- phpunit/phpunit: ^12.2.7
- symfony/process: ^5.4.46
This package is auto-updated.
Last update: 2025-08-18 20:02:04 UTC
README
composer require bendamqui/fp
Functions
flow(callable ...$fns): Closure
Pipe functions into a new function, applying them from left to right.
$add = fn($x) => fn($y) => $x + $y; $fn = flow($add(1), $add(2), $add(4)); $fn(0); // => 7
pipe(mixed $value, callable ...$fns): mixed
Pipe a value through functions from left to right.
$add = fn($x) => fn($y) => $x + $y; pipe(0, $add(1), $add(2), $add(4)); // => 7
compose(callable ...$fns): Closure
Compose functions into a new function, applying them from right to left.
$add = fn($x) => fn($y) => $x + $y; $fn = compose($add(1), $add(2), $add(3)); $fn(0); // => 6