Re:Curried Javascript Functions
by marcmarc on Monday July 20, 2009 @05:39AM
(#714213)
Here's my take:
[ Parent
| on HN ]
Re:Curried Javascript Functions
by shaunxcode on Monday July 20, 2009 @03:41PM
(#715009)
Here is curry in php 5.3
function curry(){
$args = func_get_args();
$fn = array_shift($args);
return function() use(&$fn, &$args) {
$nargs = func_get_args();
foreach($nargs as $narg) $args[] = $narg;
return call_user_func_array($fn, $args);
};
}
$add20 = curry(function($a, $b){return $a + $b;}, 20);
echo $add20(5); #25Both of our implementations have broken this. Damn you, Javascript this.
In principle, these two lines of code should always produce the same result:
foo.bar(1,2)
and foo.bar(1)(2)
And they won't necessarily in our case, if the function uses this.