API reference › @evolu/common › Function › identity
function identity<A>(a: A): A;
Defined in: packages/common/src/Function.ts:124
Returns the value unchanged.
Useful as a default transformation, placeholder callback, or when a function is required but no transformation is needed.
Example
import { assertEqual, assertSame, identity } from "@evolu/common";
const values = [1, 2, 3];
const object = { value: 1 };
const getTransform = (shouldDouble: boolean) =>
shouldDouble ? (value: number) => value * 2 : identity;
assertEqual(values.map(identity), [1, 2, 3]);
assertSame(identity(object), object);
assertEqual(getTransform(false)(2), 2);