@jiminp/tooltool
    Preparing search index...

    Function batched

    • Yields elements from a generator in batches of size n.

      Type Parameters

      • T

        Element type.

      Parameters

      • gen: Generator<T>

        The source generator (sync or async).

      • n: number

        Nonnegative integer batch size; 0 collects the complete source.

      Returns Generator<T[]>

      A generator yielding batches; an empty source yields no batches.

      If n is negative, fractional, or nonfinite.

      Positive sizes yield arrays of up to n elements, including a final partial batch. Size 0 yields one array only after the source finishes, using memory proportional to the entire source; an infinite source never yields a batch and can exhaust memory. Invalid sizes throw when batched() is called. Exiting a batch loop early closes the source generator.

      [...batched(range(10), 3)]; // [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9]]
      
    • Yields elements from a generator in batches of size n.

      Type Parameters

      • T

        Element type.

      Parameters

      • gen: AsyncGenerator<T>

        The source generator (sync or async).

      • n: number

        Nonnegative integer batch size; 0 collects the complete source.

      Returns AsyncGenerator<T[]>

      A generator yielding batches; an empty source yields no batches.

      If n is negative, fractional, or nonfinite.

      Positive sizes yield arrays of up to n elements, including a final partial batch. Size 0 yields one array only after the source finishes, using memory proportional to the entire source; an infinite source never yields a batch and can exhaust memory. Invalid sizes throw when batched() is called. Exiting a batch loop early closes the source generator.

      [...batched(range(10), 3)]; // [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9]]