2017 © Pedro Peláez
 

library compose

Function to compose functions

image

yuyat/compose

Function to compose functions

  • Wednesday, October 1, 2014
  • by yuya-takeyama
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

yuyat\compose

Function to compose functions., (*1)

Function-composition is commonly used technique in functional programming.
You can combine any callable's to build another function., (*2)

This library only supports PHP 5.6 later.
If you use the other version, igorw/compose is useful., (*3)

Usage

yuyat\compose

Calling compose($f, $g, $h) with an argument $x is equal to $f($g($h($x))), (*4)

<?php
use function yuyat\compose;

$splitAsWords = function ($str) {
    return \preg_split('/\s+/u', $str);
};
$camelizeWords = function ($words) {
    return \array_map('ucfirst', $words);
};
$join = function ($words) {
    return \join('', $words);
};
$lowerCamelize = compose('lcfirst', $join, $camelizeWords, $splitAsWords);

echo $lowerCamelize('foo bar baz'); // => "fooBarBaz"

yuyat\pipeline

This function also combines functions, but the arguments order is reversed.
Functions are applied in order of your reading., (*5)

Calling pipeline($f, $g, $h) with an argument $x is equal to $h($g($f($x))), (*6)

Author

Yuya Takeyama, (*7)

The Versions

01/10 2014

dev-master

9999999-dev

Function to compose functions

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires