Skip to content

Instantly share code, notes, and snippets.

@THEtheChad
Created October 20, 2013 03:10
Show Gist options
  • Save THEtheChad/7064524 to your computer and use it in GitHub Desktop.
Save THEtheChad/7064524 to your computer and use it in GitHub Desktop.
Curry & AutoCurry
function toArray(arr, start){ return Array.prototype.slice.call(arr, start || 0) }
Function.prototype.curry = function(){
var __method = this, args = toArray(arguments);
return function(){
return __method.apply(this, args.concat(toArray(arguments)));
}
}
Function.prototype.autoCurry = function(numArgs){
var __method = this;
numArgs = numArgs || __method.length;
return function autoCurried(){
var args = toArray(arguments)
, remaining = numArgs - args.length
;//var
return remaining > 0 ?
__method.curry.apply(__method, args).autoCurry(remaining) :
__method.apply(__method, args);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment