Skip to content

Instantly share code, notes, and snippets.

@cem2ran
Last active December 16, 2015 01:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cem2ran/06a29350d807aaba9d82 to your computer and use it in GitHub Desktop.
Save cem2ran/06a29350d807aaba9d82 to your computer and use it in GitHub Desktop.
Auto-currying for the masses
Function.prototype.curried = function (f=this) {
return (...args) => args.length < f.length
? f.curried(args.reduce((g, arg) => g.bind(null, arg), f))
: f.apply(null, args);
};
var adder = function(a,b,c) {
return a + b + c;
};
var add = adder.curried();
var add3 = add(1)(2)
console.log(add(1)(2)(3)) //=> 6
console.log(add(4,5)(6)) //=> 15
console.log(add3(5)) //=> 8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment