JavaScript

Curry Function

by @admin
10h ago
Apr 28, 2026
Public
Transforms a multi-argument function into a chain of single-argument functions. Each call returns a new function until all arguments are supplied, then the original function executes. Enables partial application and cleaner function composition pipelines.
JavaScript
function curry(fn) {
  return function curried(...args) {
    if (args.length >= fn.length) {
      return fn.apply(this, args);
    }
    return function (...more) {
      return curried.apply(this, args.concat(more));
    };
  };
}

// Usage
const add = curry((a, b, c) => a + b + c);
const add5 = add(5);
const add5and3 = add5(3);
console.log(add5and3(2)); // 10
Tags

Save your own code snippets

Create a free account and build your private vault. Share publicly whenever you want.