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

console.log(
await pipe(
asAsync([`sloth party`, `building`, `sloths in trees`, `city`]),
filterAsync(string => string.includes(`sloth`)),
reduceAsync(toArray()),
),
)
//=> [ 'sloth party', 'sloths in trees' ]

filterAsync(fn)

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

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.

Type Parameters

From

To

Parameters

fn

Returns

Function

Parameters

asyncIterable: AsyncIterable<From, any, any>

Returns

AsyncIterable<To, any, any>

Example

console.log(
await pipe(
asAsync([`sloth party`, `building`, `sloths in trees`, `city`]),
filterAsync(string => string.includes(`sloth`)),
reduceAsync(toArray()),
),
)
//=> [ 'sloth party', 'sloths in trees' ]

Defined in

filters.d.ts:65

filterAsync(fn, asyncIterable)

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

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.

Type Parameters

From

To

Parameters

fn

asyncIterable: AsyncIterable<From, any, any>

Returns

AsyncIterable<To, any, any>

Example

console.log(
await pipe(
asAsync([`sloth party`, `building`, `sloths in trees`, `city`]),
filterAsync(string => string.includes(`sloth`)),
reduceAsync(toArray()),
),
)
//=> [ 'sloth party', 'sloths in trees' ]

Defined in

filters.d.ts:68

filterAsync(fn)

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

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.

Type Parameters

Value

Parameters

fn

Returns

Function

Parameters

asyncIterable: AsyncIterable<Value, any, any>

Returns

AsyncIterable<Value, any, any>

Example

console.log(
await pipe(
asAsync([`sloth party`, `building`, `sloths in trees`, `city`]),
filterAsync(string => string.includes(`sloth`)),
reduceAsync(toArray()),
),
)
//=> [ 'sloth party', 'sloths in trees' ]

Defined in

filters.d.ts:73

filterAsync(fn, asyncIterable)

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

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.

Type Parameters

Value

Parameters

fn

asyncIterable: AsyncIterable<Value, any, any>

Returns

AsyncIterable<Value, any, any>

Example

console.log(
await pipe(
asAsync([`sloth party`, `building`, `sloths in trees`, `city`]),
filterAsync(string => string.includes(`sloth`)),
reduceAsync(toArray()),
),
)
//=> [ 'sloth party', 'sloths in trees' ]

Defined in

filters.d.ts:76