Functions
Currying
Transforming a multi-arg function into a chain of single-arg functions.
Currying converts a function that takes many arguments into a sequence of functions that each take one, using closures to remember the earlier arguments.
Currying is ordering a coffee one choice at a time — size, then milk, then sugar — instead of shouting the whole order at once.
Key concepts
1
It enables partial application — fixing some arguments now and supplying the rest later — which is great for building specialised functions from general ones.
partial application
2
Currying is a favourite interview exercise because writing a generic curry helper tests your grasp of closures, recursion and fn.length.
curryfn.length
javascript
const add = a => b => c => a + b + c;
add(1)(2)(3); // 6
const addTen = add(10);
addTen(5)(1); // 16
// Partial application
const multiply = (a, b) => a * b;
const triple = multiply.bind(null, 3);
triple(5); // 15