• Reduce an array, or a promise of an array, which contains a promises (or a mix of promises and values) with the given reducer function with the signature (total, current, index) where current is the resolved value of a respective promise in the input array. If any promise in the input array is rejected the returned promise is rejected as well.

    If the reducer function returns a promise or a thenable, the result for the promise is awaited for before continuing with next iteration.

    The original array is not modified. If no initialValue is given and the array doesn't contain at least 2 items, the callback will not be called and undefined is returned. If no initialValue is given and the array contains at least two items, the first element is used as the initial value. If initialValue is given and the array doesn't have at least 1 item, initialValue is returned.

    Type Parameters

    • T
    • U

    Parameters

    • values: Iterable<T | PromiseLike<T>, any, any> | PromiseLike<Iterable<T | PromiseLike<T>, any, any>>

      The array of values to iterate over.

    • reducer: ((total: U, current: T, index: number) => U | PromiseLike<U>)

      The reducer function.

        • (total, current, index): U | PromiseLike<U>
        • Parameters

          • total: U
          • current: T
          • index: number

          Returns U | PromiseLike<U>

    • initialValue: U

      Optional. The initial seed value for the reducer function.

    Returns Promise<U>

  • Type Parameters

    • T
    • U

    Parameters

    • values: Iterable<T | PromiseLike<T>, any, any> | PromiseLike<Iterable<T | PromiseLike<T>, any, any>>
    • reducer: ((total: U, current: T, index: number) => U | PromiseLike<U>)
        • (total, current, index): U | PromiseLike<U>
        • Parameters

          • total: U
          • current: T
          • index: number

          Returns U | PromiseLike<U>

    Returns Promise<U | undefined>