shelving
Version:
Toolkit for using data in JavaScript.
32 lines (31 loc) • 1.42 kB
TypeScript
import { ThroughSequence } from "./ThroughSequence.js";
/**
* Sequence of values that inspects a source sequence of values 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 InspectSequence(iterable);
* for await (const next of capture) console.log("YIELDED", next);
* console.log("FIRST", watch.first);
* console.log("RETURNED", watch.returned);
*/
export declare class InspectSequence<T, R, N> extends ThroughSequence<T, R, N> implements AsyncIterator<T, R, N>, AsyncIterable<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(): Promise<IteratorResult<T, R>>;
throw(thrown: unknown): Promise<IteratorResult<T, R>>;
return(value: R): Promise<IteratorResult<T, R>>;
/** Capture a result. */
private _inspect;
}