Function runningReduce

  • The runnigReduce() method executes a user-supplied "reducer" callback function on each element of the iterator, in order, passing in the return value from the calculation on the preceding element. Eaxch next call produces the result of running the reducer across all elements so far. (called scan in RxJS)

    Example

       pipe(
    itr8FromArray([ 1, 2, 3, 4 ]),
    reduce((acc, cur) => acc + cur, 0),
    );
    // => [ 1, 3, 6, 10 ]

    The reduce function can be an asynchronous function (in which case the resulting iterator will be asynchronous regardless of the input iterator)!

    Type Parameters

    • TIn

    • TOut

    Parameters

    • reducer: ((accumulator: TOut, currentValue: TIn, presentIndex?: number) => TOut | Promise<TOut>)
        • (accumulator: TOut, currentValue: TIn, presentIndex?: number): TOut | Promise<TOut>
        • Parameters

          • accumulator: TOut
          • currentValue: TIn
          • Optional presentIndex: number

          Returns TOut | Promise<TOut>

    • initialValue: TOut

    Returns TTransIteratorSyncOrAsync<TIn, TOut>

Generated using TypeDoc