UNPKG

iteragain

Version:

Javascript Iterable/Iterator/Generator-function utilities.

33 lines 1.16 kB
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. */ var ResumeIterator = /** @class */ (function () { function ResumeIterator(iterator, times) { this.iterator = iterator; this.times = times; this.values = []; } ResumeIterator.prototype[Symbol.iterator] = function () { return this; }; ResumeIterator.prototype.next = function () { var _a; var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } var next = (_a = this.iterator).next.apply(_a, 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; }; return ResumeIterator; }()); export { ResumeIterator }; export default ResumeIterator; //# sourceMappingURL=ResumeIterator.js.map