chunk
chunk<
T>(iterable,size):IterableIterator<T[]>
Defined in: packages/core/src/iterable/chunk.ts:15
Yields consecutive, non-overlapping groups of size items.
The inverse of Array.prototype.flat(), which already covers the other
direction natively. A final group shorter than size is yielded as-is when
the input length is not a multiple of it.
Time complexity: O(n).
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”iterable
Section titled “iterable”Iterable<T>
The input iterable.
number
How many items per group. Must be a positive integer.
Returns
Section titled “Returns”IterableIterator<T[]>
An iterator over the groups.
Throws
Section titled “Throws”If size is not a positive integer.