iteragain
Version:
Javascript Iterable/Iterator/Generator-function utilities.
23 lines • 691 B
JavaScript
/** Drops/skips values in the input `iterator` while the predicate returns a truthy value. */
export class DropWhileIterator {
constructor(iterator, predicate) {
this.iterator = iterator;
this.predicate = predicate;
this.dropped = false;
}
[Symbol.iterator]() {
return this;
}
next(...args) {
if (this.dropped)
return this.iterator.next(...args);
let next;
do
next = this.iterator.next(...args);
while (!next.done && this.predicate(next.value));
this.dropped = true;
return next;
}
}
export default DropWhileIterator;
//# sourceMappingURL=DropWhileIterator.js.map