Created
October 27, 2015 20:02
-
-
Save sebdesign/b5e90d8f51060a0f50c8 to your computer and use it in GitHub Desktop.
PHP Curry
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function curry(callable $function) | |
{ | |
$args = array_slice(func_get_args(), 1); | |
return function() use ($function, $args) { | |
return call_user_func_array($function, array_merge($args, func_get_args())); | |
}; | |
} |
@coderofsalvation I'm not passing just strings. The callable
hint accepts strings (function names), closures, anonymous functions, as well as array notation (['object/class', 'method']
).
Closure ⊆ callable
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you might prefer passing closures over strings: https://gist.github.com/coderofsalvation/b011bb0f6789044b4da1