• Calls a callback function for all the elements in an Iterable. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.

    Works like Array.prototype.reduce.

    Example

    Sum all numbers

    const sum = reduce((acc, curr) => acc + curr, 0);
    const result = sum([1, 2, 3]);
    console.log(result); // 6

    See

    filter, flatMap, map and sum for similar operations.

    Returns

    the reduced value

    Type Parameters

    • T

      the Iterable value type

    • U

      the reduce result type

    Parameters

    • reducerFn: ((previousValue: U, currentValue: T) => U)

      the reducer Fucntion

        • (previousValue: U, currentValue: T): U
        • Parameters

          • previousValue: U
          • currentValue: T

          Returns U

    • initialValue: U

      the value for the first call of reducerFn

    Returns ((iterable: Iterable<T>, result?: U) => U)

      • (iterable: Iterable<T>, result?: U): U
      • Parameters

        • iterable: Iterable<T>
        • result: U = initialValue

        Returns U

Generated using TypeDoc