Function: filterAsync()
Returns an async iterable that contains the values of asyncIterable
in
iteration order excluding the values for which fn
returns a value awaitable
to a falsy value.
Like Array.prototype.filter
, but for async iterables.
Example
import { asAsync, filterAsync, pipe, reduceAsync, toArray } from 'lfi'
const API_URL = `https://api.dictionaryapi.dev/api/v2/entries/en`
console.log(
await pipe(
asAsync([`sloth`, `lazy`, `sleep`]),
filterAsync(async word => {
const response = await fetch(`${API_URL}/${word}`)
const [{ meanings }] = await response.json()
return meanings.some(meaning => meaning.partOfSpeech === `adjective`)
}),
reduceAsync(toArray()),
),
)
//=> [ 'lazy' ]
Since
v0.0.1
Call Signature
filterAsync<
From
,To
>(fn
): (asyncIterable
) =>AsyncIterable
<To
,any
,any
>
Type Parameters
• From
• To