Skip to content

flatten

flatten<T>(iterable): IterableIterator<T>

Defined in: packages/core/src/iterable/flatten.ts:17

Lazily concatenates an iterable of iterables, one level deep.

The counterpart of Array.prototype.flat(), and the same operation concat performs — this one takes the sources as a single iterable rather than as arguments, so it can flatten a stream of streams.

A string is an Iterable<string>, so an Iterable<string> satisfies this signature and flattens to characters. That is what the type says; use flattenDeep, which never descends into a string, if that is not wanted.

Time complexity: O(1) to construct; O(n) total across every inner iterable.

T

Iterable<Iterable<T, any, any>>

The iterable of iterables to flatten.

IterableIterator<T>

An iterator over every element of every inner iterable, in order.