Function chunks

  • Yields non-overlapping chunks (tuples) of length from the input iterator.

    Type Parameters

    Parameters

    • arg: T
    • length: Size

      The length of each chunk, must be greater than 0.

    • Optionalfill: IterSource<T>

      Optional, the value to fill the last chunk with if it's not the same length as the rest of the iterator.

    Returns IterableIterator<Tuple<IterSource<T>, Size>>

    [...chunks([1,2,3,4,5,6,7,8,9], 3)] // [[1,2,3], [4,5,6], [7,8,9]]
    [...chunks([1,2,3,4,5,6,7,8,9], 2, 0)] // [[1,2], [3,4], [5,6], [7,8], [9, 0]]
  • Yields non-overlapping chunks (tuples) of length from the input iterator.

    Type Parameters

    Parameters

    • length: Size

      The length of each chunk, must be greater than 0.

    • Optionalfill: IterSource<T>

      Optional, the value to fill the last chunk with if it's not the same length as the rest of the iterator.

    Returns (arg: T) => IterableIterator<Tuple<IterSource<T>, Size>>

    [...chunks([1,2,3,4,5,6,7,8,9], 3)] // [[1,2,3], [4,5,6], [7,8,9]]
    [...chunks([1,2,3,4,5,6,7,8,9], 2, 0)] // [[1,2], [3,4], [5,6], [7,8], [9, 0]]