Functional programming utils.

2.0 2025-08-18 20:01 UTC

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