Variable: flattenAsync()
const
flattenAsync: <Value
>(asyncIterable
) =>AsyncIterable
<Value
>
Defined in: transforms.d.ts:380
Returns an async iterable that contains the values of each iterable in
asyncIterable
in iteration order.
Like Array.prototype.flat
, but for async iterables.
Type Parameters
Value
Value
Parameters
asyncIterable
AsyncIterable
<Iterable
<Value
> | AsyncIterable
<Value
>>
Returns
AsyncIterable
<Value
>
Example
import { asAsync, flattenAsync, map, 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}`)
const [{ meanings }] = await response.json()
return map(meaning => meaning.partOfSpeech, meanings)
}),
flattenAsync,
reduceAsync(toArray()),
),
)
//=> [
//=> 'noun',
//=> 'verb',
//=> 'noun',
//=> 'verb',
//=> 'adjective',
//=> 'verb'
//=> ]
Since
v0.0.1