2017 © Pedro Peláez
 

library compose

Composing function calls

image

srph/compose

Composing function calls

  • Wednesday, December 23, 2015
  • by srph
  • Repository
  • 1 Watchers
  • 0 Stars
  • 3 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

compose Build Status Latest Stable Version Total Downloads Latest Unstable Version License

Composing function calls in PHP, (*1)

Huh?

Here's a diff example (before and after):, (*2)

- $h($g($f($x)))
+ compose($h, $g, $f)(x);

More on Functional composition - Wikipedia., (*3)

Installing

composer require srph/compose

PHP >=5.4 is supported., (*4)

Usage

$square = function($n) {
    return $n * $n;
}

$pow = function($exponent) {
    return function($n) use ($exponent) {
        for (;$exponent--;) {
            $n .= $n;
        }

        return $n;
    }
}

$input = 2;
$f = compose($square, $pow(3), $square);
$f($input); // 4096

You may pass an infinite number of functions to compose(...fn): Closure., (*5)

The Versions

23/12 2015

dev-master

9999999-dev

Composing function calls

  Sources   Download

MIT

The Development Requires

by Avatar srph

07/11 2015

v0.1.0

0.1.0.0

  Sources   Download

MIT

The Development Requires

by Avatar srph