Skip to main content

Variable: forEachAsync()

const forEachAsync: {<Value>(fn): (asyncIterable) => Promise<void>; <Value>(fn, asyncIterable): Promise<void>; }

Defined in: side-effects.d.ts:209

Returns a promise that resolves when fn has been applied to each value of asyncIterable and the result of each application has been awaited.

The result of applying fn to a value is awaited before moving on to the next value.

Like Array.prototype.forEach, but for async iterables.

Call Signature

<Value>(fn): (asyncIterable) => Promise<void>

Type Parameters

Value

Value

Parameters

fn

(value) => unknown

Returns

(asyncIterable): Promise<void>

Parameters

asyncIterable

AsyncIterable<Value>

Returns

Promise<void>

Call Signature

<Value>(fn, asyncIterable): Promise<void>

Type Parameters

Value

Value

Parameters

fn

(value) => unknown

asyncIterable

AsyncIterable<Value>

Returns

Promise<void>

Example

import { asAsync, forEachAsync, mapAsync, pipe } from 'lfi'

const API_URL = `https://api.dictionaryapi.dev/api/v2/entries/en`

console.log(
await pipe(
asAsync([`sloth`, `lazy`, `sleep`]),
mapAsync(async word => {
const response = await fetch(`${API_URL}/${word}`)
return (await response.json())[0].phonetic
}),
forEachAsync(console.log),
),
)
//=> /slɑθ/
//=> /ˈleɪzi/
//=> /sliːp/
Playground

Since

v0.0.1