Skip to main content

Function: flatMapAsync()

Returns an async iterable containing the values of the async iterables returned, or resolving from promises returned, from applying fn to each value of asyncIterable in iteration order.

Like Array.prototype.flatMap, but for async iterables.

Example

console.log(
await pipe(
asAsync([`sloth`, `more sloth`, `even more sloth`]),
flatMapAsync(string => [string, string.length]),
reduceAsync(toArray()),
),
)
//=> [ 'sloth', 5, 'more sloth', 10, 'even more sloth', 15 ]

Since

v0.0.1

Call Signature

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

Type Parameters

From

To extends [] | unknown[]

Parameters

fn

(value) => MaybePromiseLike<AsyncIterable<To, any, any> | Iterable<To, any, any>>

Returns

Function

Parameters

asyncIterable

AsyncIterable<From, any, any>

Returns

AsyncIterable<To, any, any>

Defined in

transforms.d.ts:185

Call Signature

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

Type Parameters

From

To extends [] | unknown[]

Parameters

fn

(value) => MaybePromiseLike<AsyncIterable<To, any, any> | Iterable<To, any, any>>

asyncIterable

AsyncIterable<From, any, any>

Returns

AsyncIterable<To, any, any>

Defined in

transforms.d.ts:188

Call Signature

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

Type Parameters

From

To

Parameters

fn

(value) => MaybePromiseLike<AsyncIterable<To, any, any> | Iterable<To, any, any>>

Returns

Function

Parameters

asyncIterable

AsyncIterable<From, any, any>

Returns

AsyncIterable<To, any, any>

Defined in

transforms.d.ts:193

Call Signature

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

Type Parameters

From

To

Parameters

fn

(value) => MaybePromiseLike<AsyncIterable<To, any, any> | Iterable<To, any, any>>

asyncIterable

AsyncIterable<From, any, any>

Returns

AsyncIterable<To, any, any>

Defined in

transforms.d.ts:196