Skip to content

Instantly share code, notes, and snippets.

@mckomo
Last active July 5, 2016 19:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mckomo/1876cb605975fca4ce7fc81e13c73f35 to your computer and use it in GitHub Desktop.
Save mckomo/1876cb605975fca4ce7fc81e13c73f35 to your computer and use it in GitHub Desktop.
JS implementation of curry function with some ES6 sugar.
function curry(fn) {
const arity = fn.length;
const curring = function() {
var args = asArray(arguments);
if (args.length >= arity) {
return fn(... args);
}
return function() {
return curring(... args.concat(asArray(arguments)));
};
}
const asArray = parameters => Array.prototype.slice.call(parameters, 0);
return curring;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment