UNPKG

iteragain

Version:

Javascript Iterable/Iterator/Generator-function utilities.

24 lines 810 B
/** An iterator that collects (triplets) from the input `Iterator<T>`, like: [T, T, T]. */ export class TriplewiseIterator { constructor(iterator) { this.iterator = iterator; this.prev = []; } [Symbol.iterator]() { return this; } next(...args) { while (this.prev.length !== 3) { const next = this.iterator.next(...args); // if (next.done) return (this.next = () => ({ done: true, value: undefined }))(); if (next.done) return { done: true, value: undefined }; this.prev.push(next.value); } const value = this.prev.slice(); this.prev.shift(); return { done: false, value }; } } export default TriplewiseIterator; //# sourceMappingURL=TriplewiseIterator.js.map