docs/fp/reference/chunk.md
Creates a function that splits an array into sub-arrays of a given length. Use it with pipe.
const result = pipe(array, chunk(size));
::: info
Prefer the original es-toolkit chunk in ordinary code. Use this fp variant when composing transformations with pipe.
:::
chunk divides an array into sub-arrays, each of length size. When the array cannot be divided evenly, the final chunk holds the remaining elements.
import { chunk, pipe } from 'es-toolkit/fp';
pipe([1, 2, 3, 4, 5], chunk(2)); // => [[1, 2], [3, 4], [5]]
// A size larger than the array yields a single chunk.
pipe([1, 2, 3], chunk(10)); // => [[1, 2, 3]]
size (number): The length of each chunk. Must be a positive integer.((array: readonly T[]) => T[][]): A function that maps a readonly T[] to an array of chunks.
Throws an error if size is not a positive integer.