reduceAsync es-toolkit
Reduces an array to a single value using an async reducer function.
Reference
reduceAsync(array, reducer, initialValue)
Use reduceAsync to reduce an array to a single value by processing each element sequentially. The reducer function is applied sequentially to each element from left to right, passing the accumulated result from one call to the next.
Unlike other async array methods, reduceAsync must process elements sequentially and does not support concurrent execution, because the result from the previous step is needed for the next step.
Parameters
The array to reduce.
An async function that processes each element. It receives the accumulated value and current value, and returns the new accumulated value.
The initial value of the accumulator.
Returns
A promise that resolves to the final accumulated value.
reduceAsync(array, reducer)
When reducing an array without an initial value, the first element is used as the initial value and the reducer function is applied starting from the second element.
Calling reduceAsync on an empty array without an initial value returns undefined.
Parameters
The array to reduce.
An async function that processes each element. It receives the accumulated value and current value, and returns the new accumulated value.
Returns
A promise that resolves to the final accumulated value. Returns undefined if the array is empty.
Source: es-toolkit
Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.