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
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#