mapTuple
The mapTuple() method maps each element of an array while preserving tuple length at the type level.
Interactive example
Syntax
Classic signature
typescript
function mapTuple<
GenericInput extends readonly unknown[],
GenericOutput extends unknown
>(
input: GenericInput,
theFunction: (
element: GenericInput[number],
params: ArrayMapTupleParams<GenericInput>
) => GenericOutput
): MapTuple<GenericInput, GenericOutput>Curried signature
typescript
function mapTuple<
GenericInput extends readonly unknown[],
GenericOutput extends unknown
>(
theFunction: (
element: GenericInput[number],
params: ArrayMapTupleParams<GenericInput>
) => GenericOutput
): (input: GenericInput) => MapTuple<GenericInput, GenericOutput>Helper parameters
typescript
interface ArrayMapTupleParams<
GenericInputTuple extends readonly unknown[]
> {
index: number;
self: GenericInputTuple;
}Parameters
input: Array or tuple to transform.theFunction: Mapping function receiving current element, index, and source array.
Return value
A new mapped array. If input is a tuple, the output keeps the same tuple length.
