Function indexBy

  • Emits indexed values that pass the predicate test.

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

    const i = pipe(
    [12, 7, 30, 9],
    indexBy(a => a % 2 === 0) // index even numbers
    );

    console.log(...i); //=> {index: 0, value: 12}, {index: 2, value: 30}

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

    Type Parameters

    • T

    Parameters

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

          Returns boolean | Promise<boolean>

    Returns Operation<T, IIndexedValue<T>>