fxIdentity

Returns its argument unchanged.

T fxIdentity<T>(T a) => a;

Lecture

fxIdentity is the simplest function in the library, and one of the most useful: it takes a value and hands it straight back. On its own that looks pointless. Its value shows up whenever an API expects a function but you don't actually want to transform anything — a default key function for groupBy/sortBy, a placeholder branch in a dispatch table, or the "no-op" arm of a conditional pipeline.

Because fxIdentity is generic (T fxIdentity<T>(T a)), it slots into any unary-function position without you writing (x) => x yourself. It has no async variant and no chain form — it's a plain value-in, value-out function you pass around.

Its zero-argument sibling is fxNoop (void fxNoop()), which does nothing at all — the stand-in for a callback slot that takes no arguments and has no work to do.

Demo 1 · Basics

Used directly, and as the key function for a grouping operation where "group by the value itself" is exactly what you want:

Demo 2 · As the "do nothing" branch

A dispatch table of string transforms, where one entry deliberately does nothing — fxIdentity fills that slot cleanly instead of a hand-written no-op lambda:

Try it yourself

Exercise: sortBy takes a key function. Use fxIdentity as that key to sort this list of words by their natural (string) order.

Related: fxAlways — a constant instead of a pass-through · fxTap — pass through, but run a side effect first · fxCases — dispatch table with predicates · sortBy — a common home for a key function