Reduce for async iterables.
The reduce() method applies a function against an accumulator and each element in the async iterable (from left to right) to reduce it to a single value.
Async iterable fun
This module is part of Async iterable fun, a complete toolset of modules to work with async iterables.
Reduce to an async iterable to the sum of its elements:
;const add = accum + item;console;
This will output 6
The reduce() method applies a function against an accumulator and each element in the async iterable to reduce it to a single promise.
dataAsyncIterable The async iterable to reduce
reducerFunction Function to execute on each element in the async iterable, taking four arguments:
data - The async iterable reduce was called upon. accumulator - The accumulator accumulates the callback's return values; it is the accumulated value previously returned in the last invocation of the callback, or initialValue, if supplied (see below). currentValue - The current element being processed in the async iterable. currentIndex - The index of the current element being processed in the async iterable. Starts at index 0, if an initialValue is provided, and at index 1 otherwise.
initialValueany Value to use as the first argument to the first call of the callback. If no initial value is supplied, the first element in the async iterable will be used. Calling reduce on an empty async iterable without an initial value is an error.
Returns Promise The promise value that results from the reduction.
Higher order function that partially apply
to the reduce function.
reducerFunction The reducer argument to partially apply
accumulatorany The accumulator argument to partially apply
reduce unary function that take a data argument
With npm installed, run
npm install --save ai-reduce