Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/iter/lib/transformers.ts>chunkify

A bunch of utilities for working with iterables, many inspired by the native array methods.
Latest
function chunkify
import { chunkify } from "https://deno.land/x/iter@v3.2.3/lib/transformers.ts";

Splits an iterable into evenly sized chunks. See @sindresorhus/chunkify

Examples

Example 1

import * as iter from "https://deno.land/x/iter/mod.ts";

const naturals = iter.create.increments(-1, -1);
const chunks = iter.chunkify(naturals, 3);
const iterator = chunks[Symbol.iterator]();

console.log(iterator.next().value); // -> [ -1, -2, -3 ]
console.log(iterator.next().value); // -> [ -4, -5, -6 ]
console.log(iterator.next().value); // -> [ -7, -8, -9 ]
console.log(iterator.next().value); // -> [ -10, -11, -12 ]
console.log(iterator.next().value); // -> [ -13, -14, -15 ]
console.log(iterator.next().value); // -> [ -16, -17, -18 ]

Parameters

it: Iterable<T>
  • The iterable being chunkified.
chunkSize: number
  • The size of each chunk.

Returns

A new iterable over chunk arrays.