UNPKG

iteragain

Version:

Javascript Iterable/Iterator/Generator-function utilities.

26 lines 844 B
import toIterator from '../toIterator'; /** * Continues iterating through the input `iterator` a certain number of times. When the input iterator is done it * returns `{ done: true, value: undefined }` first before resuming back to the beginning again. */ export class ResumeIterator { constructor(iterator, times) { this.iterator = iterator; this.times = times; this.values = []; } [Symbol.iterator]() { return this; } next(...args) { const next = this.iterator.next(...args); if (next.done && this.times-- > 0) { this.iterator = toIterator(this.values.splice(0, this.values.length)); return next; } this.values.push(next.value); return next; } } export default ResumeIterator; //# sourceMappingURL=ResumeIterator.js.map