Skip to content

Latest commit

 

History

History
39 lines (27 loc) · 780 Bytes

compose.md

File metadata and controls

39 lines (27 loc) · 780 Bytes

compose

Description

Takes a set of functions and returns another that is the composition of those $fns. The result of the first function is used as unique argument of the second one and the result of this for the third function and so on...

It's usually used in combination with apply function.

Parameters

fns
Functions to be composed.

Examples

Multiply 2 numbers and divide the previous result by two:

<?php

use function Lambdish\Phunctional\apply;
use function Lambdish\Phunctional\compose;

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

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

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

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