Functional programming utils.

v1.0 2020-03-24 22:46 UTC

This package is auto-updated.

Last update: 2024-05-25 13:38:58 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