Skip to main content
Module

x/itertools/more-itertools.ts>chunked

🦕 A TypeScript port of Python's itertools and more-itertools for Deno
Latest
function chunked
import { chunked } from "https://deno.land/x/itertools@v1.1.2/more-itertools.ts";

Break iterable into lists of length size:

[...chunked([1, 2, 3, 4, 5, 6], 3)]
// [[1, 2, 3], [4, 5, 6]]

If the length of iterable is not evenly divisible by size, the last returned list will be shorter:

[...chunked([1, 2, 3, 4, 5, 6, 7, 8], 3)]
// [[1, 2, 3], [4, 5, 6], [7, 8]]

Parameters

iterable: Iterable<T>
size: number

Returns

Iterable<Array<T>>