Skip to content

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 transform
  • theFunction: Transformation function that receives:
    • arg: The current element
    • params.index: The element index

Return value ​

A new Generator emitting the transformed values.

See also ​

  • asyncMap - Asynchronous version of map
  • filter - Filters the elements of a generator
  • reduce - Reduces a generator to a value

Sources ​

Released under the MIT license.