Skip to main content

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' ]
Playground

Since

v0.0.1

Call Signature

filterAsync<From, To>(fn): (asyncIterable) => AsyncIterable<To, any, any>

Type Parameters

From

To

Parameters

fn

(value) => value is To

Returns

Function

Parameters

asyncIterable

AsyncIterable<From, any, any>

Returns

AsyncIterable<To, any, any>

Defined in

filters.d.ts:77

Call Signature

filterAsync<From, To>(fn, asyncIterable): AsyncIterable<To, any, any>

Type Parameters

From

To

Parameters

fn

(value) => value is To

asyncIterable

AsyncIterable<From, any, any>

Returns

AsyncIterable<To, any, any>

Defined in

filters.d.ts:80

Call Signature

filterAsync<Value>(fn): (asyncIterable) => AsyncIterable<Value, any, any>

Type Parameters

Value

Parameters

fn

(value) => unknown

Returns

Function

Parameters

asyncIterable

AsyncIterable<Value, any, any>

Returns

AsyncIterable<Value, any, any>

Defined in

filters.d.ts:85

Call Signature

filterAsync<Value>(fn, asyncIterable): AsyncIterable<Value, any, any>

Type Parameters

Value

Parameters

fn

(value) => unknown

asyncIterable

AsyncIterable<Value, any, any>

Returns

AsyncIterable<Value, any, any>

Defined in

filters.d.ts:88