2017 © Pedro PelĂĄez
 

library auto-curry

Provides automatic currying of functions and methods.

image

m4rw3r/auto-curry

Provides automatic currying of functions and methods.

  • Monday, November 18, 2013
  • by m4rw3r
  • Repository
  • 3 Watchers
  • 9 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

autoCurry

Build Status, (*1)

Enables automatic currying of functions. Every call to an autoCurryed function will return a new function accepting the remaining function parameters until all parameters have been gathered whereupon the wrapped function will be executed and return its value., (*2)

Note that the function not only works on other functions, it also works on objects implementing __invoke(), closures, static methods and standard object methods., (*3)

To see how autoCurry can help you write very terse code, watch this video: Hey underscore, you're doing it wrong!, (*4)

Usage

$add = m4rw3r\autoCurry(function($a, $b) {
    return $a + $b;
});

$add5 = $add(5);

var_dump($add5(3)); /* int(8) */

$concat = m4rw3r\autoCurry(function($a, $b) {
    return $a . $b;
});

$namePrefix = $concat('Test');

$names = array_map($namePrefix, ['Foo', 'Bar']);
/* array(2) { [0] => string(7) "TestFoo" [1] => string(7) "TestBar" } */

Prototype

callable m4rw3r\autoCurry(callable [, num_params = false])
  • callable: The function/closure/method/object to curry
  • num_params: Sets the limit for the auto-curry, useful in cases where optional parameters are present or when a method accepting any number of parameters is being curryed.

autoCurry() will automatically determine the number of parameters if num_params is false, through the use of ReflectionMethod and ReflectionFunction., (*5)

The Versions

18/11 2013

dev-master

9999999-dev

Provides automatic currying of functions and methods.

  Sources   Download

MIT

by Martin WernstÄl

functional currying