Last Updated: February 25, 2016
·
769
· nmichel

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

1 Response
Add your 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 ·