Skip to content

Instantly share code, notes, and snippets.

@stevekane
Created December 3, 2013 05:11
Show Gist options
  • Save stevekane/7764181 to your computer and use it in GitHub Desktop.
Save stevekane/7764181 to your computer and use it in GitHub Desktop.
Curry example for future reference
/**
first arg is a function, second is the number of arguments
to expect before executing
(N.B. The second arg is optional and will default to the arity
of the function if not provided)
*/
function curry (fn, numArgs) {
var numArgs = numArgs || fn.length;
function makeCurried (previousArgs) {
return function () {
var args = previousArgs.concat(Array.prototype.slice.call(arguments));
if (args.length < numArgs) return makeCurried(args);
return fn.apply(this, args);
}
}
return makeCurried([]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment