Iterator chunking

Specification: proposal-iterator-chunking

Modules

esnext.iterator.chunks, esnext.iterator.sliding and esnext.iterator.windows

class Iterator {
  chunks(chunkSize: number): Iterator<any>;
  sliding(windowSize: number): Iterator<any>;
  windows(windowSize: number): Iterator<any>;
}

CommonJS entry points

core-js/proposals/iterator-chunking
core-js(-pure)/full/iterator/chunks
core-js(-pure)/full/iterator/sliding
core-js(-pure)/full/iterator/windows

Examples

const digits = () => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].values();

let chunksOf2 = Array.from(digits().chunks(2));  // [ [0, 1], [2, 3], [4, 5], [6, 7], [8, 9] ]

let slidingOf2 = Array.from(digits().sliding(2));  // [ [0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9] ]

let windowsOf2 = Array.from(digits().windows(2));  // [ [0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9] ]