UNPKG

iteragain

Version:

Javascript Iterable/Iterator/Generator-function utilities.

31 lines 1.28 kB
import type { Tuple } from '../types'; /** * Wraps `iterator` to allow for seeking backwards and forwards. An internal cache of length `maxLength` is kept and * progressively added to when iterating forwards. */ export declare class SeekableIterator<T> implements IterableIterator<T> { protected iterator: Iterator<T>; protected maxLength: number; protected cache: T[]; protected i: number; protected iteratorDone: boolean; constructor(iterator: Iterator<T>, maxLength?: number); get elements(): readonly T[]; get done(): boolean; [Symbol.iterator](): IterableIterator<T>; next(...args: any[]): IteratorResult<T>; /** * Seeks forward/backwards to the index `i`. `i` may be any positive or negative number. Negative numbers seek * starting from the end of the internal cache (e.g. -1 is the last element). */ seek(i: number): void; /** * Peek ahead of where the current iteration is. This doesn't consume any values of the iterator. * @param ahead optional, the number of elements to peek ahead. */ peek<N extends number = 1>(ahead?: N): Tuple<T, N>; /** Add `value` to the `cache`. */ private add; } export default SeekableIterator; //# sourceMappingURL=SeekableIterator.d.ts.map