map
The map() function transforms each element of a generator by applying a transformation function. It returns a new generator with the transformed values.
Interactive example
Syntax
Classic signature
typescript
function map<
const GenericInput extends unknown,
const GenericOutput extends unknown,
>(
iterator: Iterable<GenericInput>,
theFunction: (
arg: GenericInput,
params: GeneratorMapParams
) => GenericOutput
): Generator<GenericOutput, unknown, unknown>Curried signature
typescript
function map<
const GenericInput extends unknown,
const GenericOutput extends unknown,
>(
theFunction: (
arg: GenericInput,
params: GeneratorMapParams
) => GenericOutput
): (iterator: Iterable<GenericInput>) => Generator<GenericOutput, unknown, unknown>Parameters
iterator: The generator to transformtheFunction: Transformation function that receives:arg: The current elementparams.index: The element index
Return value
A new Generator emitting the transformed values.
See also
asyncMap- Asynchronous version of mapfilter- Filters the elements of a generatorreduce- Reduces a generator to a value
