Advanced Function Patterns: Currying and Partial Application in Javascript


Use currying and partial application to create more reusable code.

Source Code

function curry(fn) {
  return function curried(...args) {
    if (args.length >= fn.length) {
      return fn.apply(this, args);
    } else {
      return function(...args2) {
        return curried.apply(this, args.concat(args2));
      }
    }
  };
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments