Function reduce

  • Reducer function such as Array.reduce but accepting an iterable.

    Type Parameters

    • Iter extends AnyIt<unknown>
    • V extends unknown
    • U = V

    Parameters

    • func: Reducer<U, V>
    • Optional initialValue: ValOrNotDefined<U>

    Returns CurriedAnyItResult<Iter, U>

    Example

    // Returns 6
    it.reduce([1, 2, 3], (num, acc) => num + acc)

    Example

    // Returns 7
    it.reduce([1, 2, 3], (num, acc) => num + acc, 1)