shelving
Version:
Toolkit for using data in JavaScript.
32 lines (31 loc) • 1.36 kB
TypeScript
import { ThroughIterator } from "./ThroughIterator.js";
/**
* Iterable that inspects a source iterable as it iterates.
* - Stores: first/last yielded value, returned value, whether iteration is done, the number of items that were iterated.
*
* @example
* const watch = new InspectIterator(iterable);
* for (const next of capture) console.log("YIELDED", next);
* console.log("FIRST", watch.first);
* console.log("RETURNED", watch.returned);
*/
export declare class InspectIterator<T, R, N> extends ThroughIterator<T, R, N> implements Iterator<T, R, N>, Iterable<T, R, N> {
/** Get the number of results received by this iterator so far. */
readonly count = 0;
/** Is the iteration done? */
readonly done: boolean;
/** The first yielded value (throws if the iteration yielded no values, i.e. `this.count === 0`). */
get first(): T;
private _first;
/** The last yielded value (throws if the iteration yielded no values, i.e. `this.count === 0`). */
get last(): T;
private _last;
/** The returned value (throws if the iteration is not done, i.e. `this.done === false`). */
get returned(): R;
private _returned;
next(value: N): IteratorResult<T, R>;
throw(thrown: unknown): IteratorResult<T, R>;
return(value: R): IteratorResult<T, R>;
/** Capture a result. */
private _inspect;
}