Skip to content

asyncMap

La fonction asyncMap() transforme chaque élément d'un générateur en appliquant une fonction de transformation asynchrone. Retourne un générateur asynchrone avec les valeurs transformées.

Exemple interactif

Syntaxe

Signature classique

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>

Signature currifiée

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>

Paramètres

  • iterator : Le générateur (synchrone ou asynchrone) à transformer
  • theFunction : Fonction asynchrone de transformation qui reçoit :
    • arg : L'élément courant
    • params.index : L'index de l'élément

Valeur de retour

Un AsyncGenerator émettant les valeurs transformées.

Voir aussi

  • map - Version synchrone de asyncMap
  • asyncFilter - Filtre avec une fonction asynchrone
  • asyncReduce - Réduit avec une fonction asynchrone

Sources

Diffusé sous licence MIT.