ReviseAlgo Logo

Functional Programming

Currying & Partial Application

Master currying and partial application in JavaScript. Learn to split multi-argument functions into single-argument chains, bind arguments, and construct utility helpers.

Last Updated: July 15, 2026 10 min read

1. Introduction

Currying and Partial Application are functional programming techniques used to transform how functions receive arguments. Currying converts a function that accepts multiple arguments into a chain of nested functions that each accept a single argument. Partial Application binds some arguments to a function, returning a new function that accepts the remaining arguments.

2. Why It Matters

When working with reusable functions (like logging helpers or event listeners), some arguments remain constant (like the log prefix or configuration settings) while others change (like the log message). Currying allows you to bind these constant arguments, returning a specialized helper function.

3. Real-World Analogy

Think of a Assembly Line for Custom Burgers:

  • Standard Function (Ordering all items at once): You order a burger with a bun, patty, cheese, and sauce. The chef prepares the entire burger at once.
  • Curried Function (Chained preparation stations): The burger travels down a assembly line. Station 1 adds the bun, returning a burger waiting for a patty. Station 2 adds the patty, returning a burger waiting for cheese. Each station accepts a single ingredient, returning a product waiting for the next one.
  • Partial Application (Pre-made base): The kitchen pre-makes 50 burger bases (buns + patties already assembled). When a customer orders, the chef only needs to add the remaining ingredients (cheese and sauce). You pre-fill some settings, saving time.

4. Currying vs Partial Application

Let's contrast the implementation of the two techniques:

1. Currying:

Converts fn(a, b, c) into fn(a)(b)(c). Each returned function accepts exactly one argument.

2. Partial Application:

Binds a subset of arguments, returning a function that accepts the remaining arguments.

5. Practical Example

This script demonstrates using currying to create specialized logger functions:

6. Common Mistakes

  • Confusing currying with partial application: While similar, they are not the same. Currying splits a function into a chain of single-argument functions (e.g. f(a)(b)(c)). Partial application binds a subset of arguments, returning a function that can accept multiple remaining arguments at once (e.g. f(a, b)).

7. Quick Quiz

Q1: Which technique describes transforming a function from fn(a, b, c) into fn(a)(b)(c)?

A) Partial Application

B) Currying

Answer: B — Currying converts a function with multiple arguments into a chain of nested single-argument functions.

8. Scenario-Based Challenge

The Dynamic API Endpoints Query Resolver:

An application performs queries: fetch(domain, path, queryParams). Since the domain: https://api.myproject.com remains constant, curried helper functions can simplify the queries. Write a curried function that allows you to configure the domain once, returning helper functions to query specific endpoints.

9. Debugging Exercise

Explain why this currying helper throws a TypeError, and how to fix it:

function volume(w, h, d) {
  return w * h * d;
}

// Objective: curry the volume function const curriedVol = (w) => (h) => (d) => volume(w, h, d);

// Bug: trying to execute it with standard parameters! const result = curriedVol(10, 5, 2); // returns function (h) => ... instead of volume! Why?

View Solution

Diagnosis: The curried function curriedVol is designed as a chain of nested functions that each accept a single argument. Calling it with multiple arguments at once (curriedVol(10, 5, 2)) only passes the first argument (w = 10), ignoring the others and returning the next function in the chain.

Fix: Invoke the curried function by calling each nested function in the chain separately, or write a helper to curry the function dynamically:

const result = curriedVol(10)(5)(2); // Call each function in the chain
console.log(result); // 100

11. Interview Questions

🟢 Q1: Compare Currying and Partial Application and explain their differences.

Answer:
Currying: Converts a function that accepts multiple arguments into a chain of nested functions that each accept exactly one argument: fn(a, b, c) -> fn(a)(b)(c).
Partial Application: Binds some arguments to a function, returning a new function that accepts the remaining arguments at once: fn(a, b, c) -> fn(a)(b, c).

12. Production Considerations

  • Performance Overhead: Currying creates multiple nested function instances and closures in memory. While useful for code organization, avoid overusing currying inside high-frequency loops where performance is critical.