Function tee

  • Branches the given async iterable into the n branches.

    Type Parameters

    • T

      The type of the provided async iterable and the returned async iterables.

    • N extends number = 2

      The amount of branches to tee into.

    Parameters

    • iterable: AsyncIterable<T, any, any>

      The iterable to tee.

    • n: N = ...

      The amount of branches to tee into.

    Returns Tuple<AsyncIterable<T>, N>

    The tuple where each element is an async iterable.

    import { tee } from "@std/async/tee";
    import { assertEquals } from "@std/assert";

    const gen = async function* gen() {
    yield 1;
    yield 2;
    yield 3;
    };

    const [branch1, branch2] = tee(gen());

    const result1 = await Array.fromAsync(branch1);
    assertEquals(result1, [1, 2, 3]);

    const result2 = await Array.fromAsync(branch2);
    assertEquals(result2, [1, 2, 3]);