UNPKG

shelving

Version:

Toolkit for using data in JavaScript.

34 lines (33 loc) 1.51 kB
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> { /** Get the number of results received by this iterator so far. */ get count(): number; private _count; /** Is the iteration done? */ get done(): boolean; private _done; /** 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 | undefined; private _returned; next(value?: N | undefined): Promise<IteratorResult<T, R | undefined>>; return(value?: R | undefined | PromiseLike<R | undefined>): Promise<IteratorResult<T, R | undefined>>; throw(reason?: unknown): Promise<IteratorResult<T, R | undefined>>; /** Capture a result. */ private _inspect; }