Currying and Partial Application
Transform multi-argument functions into curried forms.
Currying and Partial Application is a free TypeScript Academy lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the TypeScript Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What Is Currying?
Currying transforms a function of many arguments into a chain of single-argument functions. Instead of f(a, b) you call f(a)(b).
The Classic Example
Here add takes one number and returns a function waiting for the next. TypeScript infers the nested function types automatically.
const add = (a: number) => (b: number) => a + b;
console.log(add(2)(3)); // 5Typing a Curried Function
The explicit type shows the chain clearly: a function returning a function. Each arrow corresponds to one argument.
type Add = (a: number) => (b: number) => number;
const add: Add = a => b => a + b;
console.log(add(10)(5)); // 15Partial Application
Partial application fixes some arguments now and supplies the rest later. With a curried function this is just calling it with fewer steps.
const add = (a: number) => (b: number) => a + b;
const add10 = add(10); // partially applied
console.log(add10(1), add10(2)); // 11 12Why Partial Application Helps
You can build specialized functions from general ones. add10 is a reusable, named tool derived from the generic add, improving readability and reuse.
Currying Three Arguments
The pattern extends to any arity. Each level captures one argument in a closure until the final value is produced.
const clamp = (min: number) => (max: number) => (x: number) =>
Math.min(Math.max(x, min), max);
const toByte = clamp(0)(255);
console.log(toByte(300), toByte(-5)); // 255 0Great for map and filter
Curried functions slot neatly into array methods because map expects a one-argument function. Partial application produces exactly that.
const mul = (a: number) => (b: number) => a * b;
const triple = mul(3);
console.log([1, 2, 3].map(triple)); // [3, 6, 9]A Generic Curry Helper
You can write a typed helper that curries a two-argument function. Generics keep the parameter and return types precise.
function curry2<A, B, R>(f: (a: A, b: B) => R) {
return (a: A) => (b: B) => f(a, b);
}
const join = curry2((a: string, b: string) => a + b);
console.log(join("foo")("bar")); // foobarClosures Capture Arguments
Currying works because each returned function closes over the earlier arguments. Those values stay alive until the final call uses them.
const greet = (greeting: string) => (name: string) =>
greeting + ", " + name;
const hi = greet("Hi");
console.log(hi("Sam")); // Hi, SamWhen Not to Curry
Currying every function can hurt readability. Reach for it when partial application is genuinely useful, such as configuring reusable helpers or composing pipelines.
Currying vs Default Args
Default parameters give defaults but not staged application. Currying gives true partial application, returning a real function you can pass around and reuse.
Quick Check
Quick check on this lesson.
Recap
Currying turns f(a, b) into f(a)(b), a chain of one-argument functions typed as nested arrows. Partial application then fixes leading arguments to build reusable specialized functions, powered by closures.
Frequently asked questions
Is the “Currying and Partial Application” lesson free?
Yes — the full text of “Currying and Partial Application” is free to read here on the web, and the TypeScript Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the TypeScript Academy course, upgrade to CoddyKit PRO.
What will I learn in “Currying and Partial Application”?
Transform multi-argument functions into curried forms. You practise TypeScript Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start TypeScript Academy?
No prior experience is required. TypeScript Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Currying and Partial Application” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this TypeScript Academy lesson?
Yes. Every TypeScript Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Pure Functions and Immutability
- Currying and Partial Application
- Function Composition with Types
- Typed pipe and flow Utilities