Function currying in javascript
After reading an interesting [but quite complex, IMHO] implementation of function currying in javascript, I decided to craft my own. I tried to keep it as simple as possible. I hope you'll enjoy it.
var curry = function(f) {
var curry_ = function(f, tl, accin) {
return function() {
var l = arguments.length,
accout = accin.concat([].splice.call(arguments, 0));
if (l + accin.length >= tl) {
return f.apply(this, accout);
}
return curry_(f, tl, accout);
};
};
return curry_(f, f.length, []);
}
Live example at :
http://embed.plnkr.co/jdRaYCDRp7kdHzVUNk93/preview
Written by Nicolas
Related protips
1 Response
Nice implementation! I'm working on a nodejs currying module https://github.com/stoeffel/chickencurry.
Would be nice to get some feedback.
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Functional
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#