All files / util iterator.ts

100% Statements 11/11
100% Branches 0/0
100% Functions 5/5
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24    58x 2419x     7580x 7580x       2416x       58x   7580x 7580x       58x  
export type UndefIterator<T> = () => undefined | T;
 
export class UndefEndIter<T> implements IterableIterator<T> {
  constructor(private readonly i: UndefIterator<T>) {}
 
  public next(): IteratorResult<T, T> {
    const value = this.i();
    return new IterRes(value, value === undefined) as IteratorResult<T>;
  }
 
  [Symbol.iterator]() {
    return this;
  }
}
 
export class IterRes<T> {
  constructor(
    public readonly value: T,
    public readonly done: boolean,
  ) {}
}
 
export const iter = <T>(i: UndefIterator<T>) => new UndefEndIter(i);