Skip to main content

Function: forEachConcur()

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

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

Example

import { asConcur, forEachConcur, mapConcur, pipe } from 'lfi'

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

console.log(
await pipe(
asConcur([`sloth`, `lazy`, `sleep`]),
mapConcur(async word => {
const response = await fetch(`${API_URL}/${word}`)
return (await response.json())[0].phonetic
}),
forEachConcur(console.log),
),
)
// NOTE: This order may change between runs
//=> /slɑθ/
//=> /ˈleɪzi/
//=> /sliːp/
Playground

Since

v0.0.1

Call Signature

forEachConcur<Value>(fn): (concurIterable) => Promise<void>

Type Parameters

Value

Parameters

fn

(value) => unknown

Returns

Function

Parameters

concurIterable

ConcurIterable<Value>

Returns

Promise<void>

Defined in

side-effects.d.ts:251

Call Signature

forEachConcur<Value>(fn, concurIterable): Promise<void>

Type Parameters

Value

Parameters

fn

(value) => unknown

concurIterable

ConcurIterable<Value>

Returns

Promise<void>

Defined in

side-effects.d.ts:254