2017 © Pedro Peláez
 

library curry

Function does currying

image

yuyat/curry

Function does currying

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

The README.md

yuyat\curry

Function does currying., (*1)

Virtually, it transforms functions takes multiple arguments into nested function each takes one argument like below., (*2)

f(x, y, z) => f(x)(y)(z)

And it can be applicated partially. All of below means same., (*3)

f(x)(y)(z)
f(x)(y, z)
f(x, y)(z)
f(x, y, z)

Usage

Basic usage

<?php
use function yuyat\curry;

$sum = curry(function ($x, $y, $z) {
    reteurn $x + $y + $z;
});

echo $sum(1)->apply(2)->apply(3), PHP_EOL;
// => 6

echo $sum[1][2][3], PHP_EOL; // Ruby-like short syntax
// => 6

Currying functions take variadic parameters

For functions take variadic parameters, you must specify actual parameter length as 2nd argument., (*4)

<?php
use function yuyat\curry;

$sum = curry(function (/* numbers to calculate sum */) {
    $result = 0;

    foreach (func_get_args() as $arg) {
        $result += $arg;
    }

    return $result;
}, 3);

echo $sum(1)->apply(2)->apply(3), PHP_EOL;
// => 6

Author

Yuya Takeyama, (*5)

The Versions

13/10 2014

dev-master

9999999-dev

Function does currying

  Sources   Download

MIT

The Requires

 

The Development Requires

13/10 2014

v0.9.0

0.9.0.0

Function does currying

  Sources   Download

MIT

The Requires

 

The Development Requires