Course contentsShow
← JavaScript
Lesson 1789 of 2,72337. Functional Programming PatternsFree lesson

Unary Functions and Point-Free Compatibility

Why single-argument functions work naturally in point-free style and multi-argument functions don't.

Unary Functions and Point-Free Compatibility

You'll learn: Why single-argument functions fit naturally into point-free style, while multi-argument functions create friction.

The Shape Problem

Point-free style works by passing functions directly as arguments, but here's the catch: the function's signature must match what the caller expects. Most JavaScript methods (like map, filter, reduce) call your callback with multiple arguments, but many functions only care about the first one.

A unary function accepts exactly one argument. These are point-free style's best friends because they ignore extra arguments automatically:

const double = x => x * 2;
[1, 2, 3].map(double); // ✅ [2, 4, 6]
// map calls: double(1, 0, array), double(2, 1, array), etc.
// But double only uses the first argument — perfect!

When Multi-Argument Functions Break Point-Free

Multi-argument functions accept the extra arguments and often misinterpret them:

const add = (a, b) => a + b;
[1, 2, 3].map(add); // ❌ [1, 3, 5] — unexpected!
// map calls: add(1, 0), add(2, 1), add(3, 2)
// The INDEX becomes the second number!

To use add point-free, you'd curry it first ([1, 2, 3].map(add(10))), making it temporarily unary.

The Unary Wrapper

Sometimes you need to force a function to ignore extra arguments:

const unary = fn => arg => fn(arg);

['1', '2', '3'].map(parseInt); // ❌ [1, NaN, NaN]
['1', '2', '3'].map(unary(parseInt)); // ✅ [1, 2, 3]

Key Takeaway: Unary functions naturally fit point-free style because they ignore extra arguments; multi-argument functions need currying or wrapping to avoid unexpected behavior when passed directly to array methods or composition helpers.