History of Idiom 37 > diff from v29 to v30
Edit summary for version 30 by ricardo_sdl:
New PHP implementation by user [ricardo_sdl]
New PHP implementation by user [ricardo_sdl]
↷
Version 29
2018-05-15, 18:35:35
Version 30
2018-08-23, 01:48:53
Idiom #37 Currying
Transform a function that takes multiple arguments into a function for which some of the arguments are preset.
Idiom #37 Currying
Transform a function that takes multiple arguments into a function for which some of the arguments are preset.
Extra Keywords
curryExtra Keywords
curryCode
function curry($f, ...$argsCurried) {
return function(...$args) use($f, $argsCurried) {
$finalArgs = array_merge($argsCurried, $args);
return call_user_func_array($f, $finalArgs);
};
}
function add($n1, $n2) {
return $n1 + $n2;
}
$addFive = curry('add', 5);
echo $addFive(2), PHP_EOL;
echo $addFive(-5), PHP_EOL;
Comments bubble