Skip to content

tee

tee<T>(iterable, count?): IterableIterator<T, any, any>[]

Defined in: packages/core/src/iterable/tee.ts:21

Fans one iterable out to count independent iterators over the same elements.

An iterator cannot be restarted, so anything one branch has read that another has not yet reached is buffered — the span between the slowest and the fastest consumer, and nothing more. Consumers read at their own pace; a branch that is never advanced pins the buffer at its position, so an abandoned branch should be left out of count rather than ignored.

Reading the branches in lockstep keeps the buffer at one element. Draining one branch fully before starting the next buffers the whole source.

Time complexity: O(1) amortised per element per branch. Memory: O(span).

T

Iterable<T>

The iterable to fan out.

number = 2

How many branches to produce. Must be a non-negative integer.

IterableIterator<T, any, any>[]

One iterator per branch, each yielding every element of the source.

If count is not a non-negative integer.