Skip to main content

Function: tee()

tee<ElementType>(iterable: IterableResolvable<ElementType>, count: number): IterableIterator<ElementType>[]

Creates count independent iterators from the input iterable.

Type parameters

Type parameter
ElementType

Parameters

ParameterTypeDescription
iterableIterableResolvable<ElementType>An iterator to tee.
countnumberThe number of iterators to create.

Returns

IterableIterator<ElementType>[]

An array of count iterators that each yield the same values as the input iterator.

Example

import { tee } from '@sapphire/iterator-utilities';

const iterable = [1, 2, 3, 4, 5];
const [iter1, iter2] = tee(iterable, 2);
console.log([...iter1]);
// Output: [1, 2, 3, 4, 5]

console.log([...iter2]);
// Output: [1, 2, 3, 4, 5]

Source

projects/utilities/packages/iterator-utilities/src/lib/tee.ts:28