Skip to content

identity

Returns the given value unchanged

Useful as a default transform, in function composition, or as a placeholder mapper.

Available since v2.0.0

import { identity } from '@helpers4/function';
identity<T>(value: T): T
ParameterTypeDescription
valueTThe value to return

T — The same value

The value is returned as-is with its type preserved.

identity(42);       // 42
identity('hello');  // 'hello'
identity(true);     // true

Pass identity where a transform function is required but no transformation is needed.

[1, 2, 3].map(identity); // [1, 2, 3]

View source on GitHub