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).
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”iterable
Section titled “iterable”Iterable<T>
The iterable to fan out.
count?
Section titled “count?”number = 2
How many branches to produce. Must be a non-negative integer.
Returns
Section titled “Returns”IterableIterator<T, any, any>[]
One iterator per branch, each yielding every element of the source.
Throws
Section titled “Throws”If count is not a non-negative integer.