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
Parameter | Type | Description |
---|---|---|
iterable | IterableResolvable <ElementType > | An iterator to tee. |
count | number | The 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]
Defined in
projects/utilities/packages/iterator-utilities/src/lib/tee.ts:28