Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

JS Puzzles · Const

Currying

Currying transforms a multi-argument function so it can be called through successive calls such as f(a)(b)(c). The wrapper collects arguments and invokes the original function when enough have been supplied.

How it works

Currying transforms a function that accepts several arguments together into one that can receive them through successive calls. A wrapper stores previously received arguments and invokes the original function once the required count is available.

Syntax

curry(func)

Parameters

NameTypeDescription
funcFunctionThe function to transform into a curried callable.

Returns

A wrapper function that accepts arguments incrementally and calls the original function after receiving enough arguments.

Key points

  • Currying changes a function's calling form rather than changing the operation it performs.
  • A multi-argument call can be represented as a sequence of one-argument calls.
  • The curry operation returns a transformed wrapper; the original function runs only after enough arguments arrive.
  • The helper returns a wrapper that begins collecting arguments for the original function.
  • Each partial call can retain earlier arguments through a closure.

Common mistakes

  • Creating a curried function changes how it can be called; it does not execute the original function immediately.
  • A practical JavaScript curry helper may support supplying all arguments at once as well as providing them in stages.

Example: Curry a function

function curry(fn) {
  return function curried(...args) {
    if (args.length >= fn.length) return fn(...args);
    return (...next) => curried(...args, ...next);
  };
}

const sum3 = (a, b, c) => a + b + c;
const curriedSum3 = curry(sum3);

console.log(curriedSum3(1)(2)(3));
console.log(curriedSum3(1, 2)(3));

This implementation collects arguments until it has enough to invoke the original function, supporting both chained and mixed calls.

When to use it

Create reusable partial functions

Build specialized functions by pre-supplying some arguments.

Chain function calls

Compose data-processing or configuration pipelines.

Handle staged inputs

Adapt APIs that provide values one at a time.

  • partial application
  • closures
  • lexical environment
  • _.curry

Source: Currying. Checked 2026-10-15.