Skip to content

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 to 1.

Return value ​

A lazy AsyncGenerator emitting the flattened values. Synchronous iterables nested inside an async source are also supported.

See also ​

  • flat - Synchronous flattening version
  • asyncMap - Transforms a generator with an async function
  • asyncFilter - Filters a generator with an async predicate

Released under the MIT license.