Home > polyethylene > PolyAsyncIterable > reduce
Returns the result of calling the passed reducer
for all elements of the iteration and the result of the previous call to reducer
, starting by passing init
.
Signature:
reduce<U>(reducer: AsyncIndexedReducer<T, U>, init: U): Promise<U>;
Parameter | Type | Description |
---|---|---|
reducer | AsyncIndexedReducer<T, U> | A function to call for all elements with the result of a previous call |
init | U | First element to be passed to the reducer function |
Returns:
Promise<U>
A promise the result to continually call reducer
with all elements and the previous result
reducer
will be called with the accumulated result, the next element of the iteration, and the index of the iteration. The resolved return value will be the value passed to the next call as the first argument, or the value returned if no more elements remain.