Flip, Reverse, and Sticking to Names Everyone Already Knows

An adapter for when a function's arguments arrive in the wrong order, and why inventing your own name for it is usually a mistake.

September 9, 20262 min read12 / 27

Unary and binary fix a mismatch in how many arguments a function receives. Sometimes the count is already right, and the problem is the order.

When the Order Is Wrong

Say you have a plain binary function:

JavaScript
function subtract(a, b) { return a - b; } subtract(10, 3); // 7

Somewhere else in your code, values naturally arrive in the opposite order, and you need subtract to treat the second one as a. Rewriting subtract itself would break every other place already calling it correctly.

The Adapter: Flip

JavaScript
function flip(fn) { return function (arg1, arg2, ...rest) { return fn(arg2, arg1, ...rest); }; } const subtractFlipped = flip(subtract); subtractFlipped(10, 3); // 3 - 10 = -7

flip takes a function and returns a new one that swaps only the first two arguments before calling the original. Everything after those first two passes through untouched.

This name isn't something this series made up. flip is the name nearly every functional programming library uses for exactly this adapter, the same way map and filter mean the same thing everywhere you find them.

Why Using the Standard Name Actually Matters

It would be easy to call this swapFirstTwo or reverseFirstArgs instead. Resist that.

Once you know what `flip` means, you recognize it everywhere, the same way you recognize 1 + 1 without re-deriving it.

A teammate who's used any functional library before sees flip(subtract) and instantly knows what it does, without opening the function. Name it swapFirstTwo instead, and that same teammate has to stop and actually read the implementation to trust it.

Consistency with what the rest of the functional programming world already calls something is worth more than a clever name of your own. Reach for the common name first. Only invent a new one when the pattern genuinely isn't standard.

When You Need More Than Two Reversed

flip only ever swaps the first two arguments. Sometimes an entire argument list needs to go in reverse, not just the first pair:

JavaScript
function reverseArgs(fn) { return function (...args) { return fn(...args.reverse()); }; } function formatDate(day, month, year) { return `${day}/${month}/${year}`; } const formatDateReversed = reverseArgs(formatDate); formatDateReversed(2026, 9, 8); // "8/9/2026"

This one is less common, and it isn't in every library the way flip is. That's fine, it's still worth having in your own toolbox for the rarer case where a full reversal, not just the first two, is what actually fits.

The next post covers a completely different kind of shape mismatch: a function expecting individual arguments when all you have is one array, or the other way around.