Function stop

  • Deprecated

    Use takeUntil instead (stop will be removed in v3.0.0).

    Stops iteration, once the predicate test passes.

    import {pipe, stop} from 'iter-ops';

    const i = pipe(
    [1, 2, 3, 4, 5, 6, 7, 8, 9],
    stop(a => a === 5) // stop when 5 is encountered
    );

    console.log(...i); //=> 1, 2, 3, 4

    Note that the predicate can only return a Promise inside an asynchronous pipeline, or else the Promise will be treated as a truthy value.

    See

    Type Parameters

    • T

    Parameters

    • cb: ((value: T, index: number, state: IterationState) => boolean | Promise<boolean>)
        • (value: T, index: number, state: IterationState): boolean | Promise<boolean>
        • Parameters

          Returns boolean | Promise<boolean>

    Returns Operation<T, T>