@mirei/ts-collections
    Preparing search index...

    Function chunk

    • Splits the sequence into contiguous subsequences containing at most the specified number of elements.

      Type Parameters

      • TElement

        Type of elements within the source iterable.

      Parameters

      • source: Iterable<TElement>

        The source iterable.

      • size: number

        Maximum number of elements to include in each chunk. Must be greater than 0.

      Returns IEnumerable<IEnumerable<TElement>>

      A sequence where each element is a chunk of the original sequence.

      Thrown when size is less than 1.

      The final chunk may contain fewer elements than size. Enumeration is deferred until the returned sequence is iterated.

      const numbers = [1, 2, 3, 4, 5, 6, 7, 8];
      const chunks = chunk(numbers, 3);
      console.log(chunks.select(c => c.toArray()).toArray()); // [[1, 2, 3], [4, 5, 6], [7, 8]]