UNPKG

iteragain

Version:

Javascript Iterable/Iterator/Generator-function utilities.

30 lines 1.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ResumeIterator = void 0; const toIterator_1 = require("../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. */ 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 = (0, toIterator_1.default)(this.values.splice(0, this.values.length)); return next; } this.values.push(next.value); return next; } } exports.ResumeIterator = ResumeIterator; exports.default = ResumeIterator; //# sourceMappingURL=ResumeIterator.js.map