method Enumerable.prototype.tee
Enumerable.prototype.tee<N extends number = 2>(n?: N): Tuple<Enumerable<T>, N>

Split the sequence into multiple identical streams.

Useful when you need to process the same data in different ways. Uses buffering internally, so be mindful of memory with large datasets.

Examples

Split into two streams

import { range } from "jsr:@j50n/proc";

const [a, b] = range({ to: 3 }).tee();

const resultA = await a.collect();  // [0, 1, 2]
const resultB = await b.collect();  // [0, 1, 2]

Type Parameters

N extends number = 2

Parameters

optional
n: N

The number of identical streams to create (default: 2).

Return Type

Tuple<Enumerable<T>, N>

A tuple of n identical Enumerables.

Usage

import { Enumerable } from ".";