Skip to content

Latest commit

 

History

History
38 lines (26 loc) · 718 Bytes

pipe.md

File metadata and controls

38 lines (26 loc) · 718 Bytes

pipe

Description

Takes a set of functions and returns a new one that is the composition of those $fns. The result from the first function execution is piped in to the second function and so on.

It's usually used in combination with the apply function.

Parameters

fns
Functions to be piped.

Examples

Multiply 2 numbers and divide the result by two:

<?php

use function Lambdish\Phunctional\apply;
use function Lambdish\Phunctional\pipe;

$multiplier = function ($a, $b) {
    return $a * $b;
};

$byTwoDivider = function ($num) {
    return $num / 2;
};

$calculator = pipe($multiplier, $byTwoDivider);

apply($calculator, [20, 10]);
// => 15