asyncMap
The asyncMap() function transforms each element of a generator by applying an asynchronous transformation function. It returns an asynchronous generator with the transformed values.
Interactive example
Syntax
Classic signature
typescript
function asyncMap<
const GenericInput extends unknown,
const GenericOutput extends unknown,
>(
iterator: AsyncIterable<GenericInput> | Iterable<GenericInput>,
theFunction: (arg: GenericInput, params: AsyncGeneratorMapParams) => Promise<GenericOutput>
): AsyncGenerator<GenericOutput, unknown, unknown>Curried signature
typescript
function asyncMap<
const GenericInput extends unknown,
const GenericOutput extends unknown,
>(
theFunction: (arg: GenericInput, params: AsyncGeneratorMapParams) => Promise<GenericOutput>
): (iterator: AsyncIterable<GenericInput> | Iterable<GenericInput>) => AsyncGenerator<GenericOutput, unknown, unknown>Parameters
iterator: The generator (synchronous or asynchronous) to transformtheFunction: Asynchronous transformation function that receives:arg: The current elementparams.index: The element index
Return value
An AsyncGenerator emitting the transformed values.
See also
map- Synchronous version of asyncMapasyncFilter- Filters with an async functionasyncReduce- Reduces with an async function
