Function: eachAsync()
Returns an async iterable equivalent to asyncIterable
that applies fn
to
each value of asyncIterable
as it is iterated.
The result of applying fn
to a value is awaited before yielding and then
moving on to the next value.
Example
import { asAsync, eachAsync, mapAsync, pipe, reduceAsync, toArray } 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
}),
eachAsync(console.log),
reduceAsync(toArray()),
),
)
//=> /slɑθ/
//=> /ˈleɪzi/
//=> /sliːp/
//=> [ '/slɑθ/', '/ˈleɪzi/', '/sliːp/' ]
Since
v0.0.1
Call Signature
eachAsync<
Value
>(fn
): (asyncIterable
) =>AsyncIterable
<Value
,any
,any
>
Type Parameters
• Value
Parameters
fn
(value
) => PromiseLike
<unknown
>
Returns
Function
Parameters
asyncIterable
AsyncIterable
<Value
, any
, any
>
Returns
AsyncIterable
<Value
, any
, any
>
Defined in
Call Signature
eachAsync<
Value
>(fn
,asyncIterable
):AsyncIterable
<Value
,any
,any
>
Type Parameters
• Value
Parameters
fn
(value
) => PromiseLike
<unknown
>
asyncIterable
AsyncIterable
<Value
, any
, any
>
Returns
AsyncIterable
<Value
, any
, any
>
Defined in
Call Signature
eachAsync<
From
,To
>(fn
): (asyncIterable
) =>AsyncIterable
<To
,any
,any
>
Type Parameters
• From
• To
Parameters
fn
(value
) => asserts value is To
Returns
Function
Parameters
asyncIterable
AsyncIterable
<From
, any
, any
>
Returns
AsyncIterable
<To
, any
, any
>
Defined in
Call Signature
eachAsync<
From
,To
>(fn
,asyncIterable
):AsyncIterable
<To
,any
,any
>
Type Parameters
• From
• To
Parameters
fn
(value
) => asserts value is To
asyncIterable
AsyncIterable
<From
, any
, any
>
Returns
AsyncIterable
<To
, any
, any
>