Skip to content

Instantly share code, notes, and snippets.

@bondarewicz
Created July 11, 2014 14:25
Show Gist options
  • Select an option

  • Save bondarewicz/e6d42f9f4f6e3362b8ce to your computer and use it in GitHub Desktop.

Select an option

Save bondarewicz/e6d42f9f4f6e3362b8ce to your computer and use it in GitHub Desktop.
PHP: currying
<?php
//http://refectoryofajumblesale.wordpress.com/2013/06/04/currying-php/
$add = function($a, $b, $c) {
return $a + $b + $c;
};
$add2 = curry($add, 2);
echo $add2(4, 5);
function curry($fn, $arg, $obj = null) {
return function() use ($fn, $arg, $obj) {
$args = func_get_args();
array_unshift($args, $arg);
if($obj) {
$fn = array($obj, $fn);
}
return call_user_func_array($fn, $args);
};
}
@coderofsalvation
Copy link

thx, I included this into a snippet of highorder funcs: https://gist.github.com/coderofsalvation/b011bb0f6789044b4da1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment