UNPKG

iteragain

Version:

Javascript Iterable/Iterator/Generator-function utilities.

23 lines 706 B
/** Take values from the input `iterator` while the predicate returns a truthy value. */ export class TakeWhileIterator { constructor(iterator, predicate) { this.iterator = iterator; this.predicate = predicate; this.done = false; } [Symbol.iterator]() { return this; } next(...args) { if (this.done) return { done: true, value: undefined }; const next = this.iterator.next(...args); if (next.done || !this.predicate(next.value)) { this.done = true; return this.next(...args); } return next; } } export default TakeWhileIterator; //# sourceMappingURL=TakeWhileIterator.js.map