asyncFlat
The asyncFlat() function flattens nested synchronous or asynchronous iterables into a single async generator. The flattening depth is configurable.
Interactive example
Syntax
typescript
function asyncFlat<
const GenericValue extends unknown,
const GenericDepth extends number = 1,
>(
iterator: AsyncIterable<GenericValue> | Iterable<GenericValue>,
depth?: GenericDepth,
): AsyncGenerator<FlatAsyncIterator<GenericValue, GenericDepth>, void, unknown>Parameters
iterator: Synchronous or asynchronous iterable to flatten.depth: Number of levels to expand. Defaults to1.
Return value
A lazy AsyncGenerator emitting the flattened values. Synchronous iterables nested inside an async source are also supported.
See also
flat- Synchronous flattening versionasyncMap- Transforms a generator with an async functionasyncFilter- Filters a generator with an async predicate
