Currying Isn't Just for Specializing Values, It's for Fixing Shape
The most common reason working functional programmers reach for currying: turning a binary function into the unary one a utility like map actually needs.
Every currying example so far has been about specializing a value: presetting an endpoint, an ID, a rate. There's a second reason to curry a function that shows up far more often in practice.
A Shape That Doesn't Fit
function applyDiscount(rate, price) {
return price - price * rate;
}
const prices = [40, 25, 100];
prices.map(applyDiscount); // wrong: map also passes an index and the arrayThis exact mismatch broke parseInt earlier in this series: .map() calls its callback with three arguments, and applyDiscount was never built to receive a stray index as its second input.
The earlier fix wrapped the function in unary. There's a more common fix used constantly in real functional code:
function tenPercentOff(price) {
return applyDiscount(0.1, price);
}
prices.map(tenPercentOff);The Same Fix, Without Writing the Wrapper
That wrapper is just a specialized, unary version of applyDiscount, which is exactly what currying produces automatically:
const curriedDiscount = curry(applyDiscount);
prices.map(curriedDiscount(0.1));curriedDiscount(0.1) returns a function expecting exactly one more argument, price, the identical unary shape map needs. No wrapper function had to be written out by hand.
Why This Is the Real Reason Currying Wins
Specializing a value, like presetting an endpoint, happens occasionally. Needing a unary function to hand to map, filter, a composition, or any other utility that expects one input happens constantly. Once every function in your toolkit is pre-curried, fixing a shape mismatch costs nothing beyond calling the function with one fewer argument than usual.
Currying, in practice, is less about "I want to lock in this value now" and more about "I need this function to have a different shape than the one it already has." Both are the same mechanism. The shape-fixing case is just the one you'll reach for far more often.
That's the last piece of closure this series needed. Everything from here builds on functions you can trust, shapes you can adapt, and values you can lock in on demand, which is exactly what composition, the next chapter, needs all three of.
Keep reading