Skip to content

Instantly share code, notes, and snippets.

@asvny
Forked from cem2ran/auto_curry.js
Created October 6, 2015 12:03
Show Gist options
  • Save asvny/47fc7f11ceabe3f380c9 to your computer and use it in GitHub Desktop.
Save asvny/47fc7f11ceabe3f380c9 to your computer and use it in GitHub Desktop.
Auto-currying for the masses
Function.prototype._curry = function (f=this) {
return (...args) => args.length < f.length
? f._curry(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._curry();
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