Aggregates/accumulates all values into array, passes it into the callback/aggregate,
to process the data and return the result. It is to simplify integration into the pipeline,
of external functions that can only operate on a complete data set.
If the callback result is an iterable that you want to emit values, follow it up with the spread operator.
It basically repeats the logic of combining toArray + map.
import {pipe, aggregate, spread} from'iter-ops';
constinput = [7, 4, 3, 8, 2, 1]; // unsorted list
consti = pipe( input, aggregate(values=>values.sort((a, b) =>a - b)), // sort the values spread() // spread aggregation result );
console.log(...i); //=> 1, 2, 3, 4, 7, 8
The aggregate callback can optionally return a Promise when inside asynchronous pipeline.
Aggregates/accumulates all values into array, passes it into the callback/aggregate, to process the data and return the result. It is to simplify integration into the pipeline, of external functions that can only operate on a complete data set.
If the callback result is an iterable that you want to emit values, follow it up with the spread operator.
It basically repeats the logic of combining toArray + map.
The aggregate callback can optionally return a
Promise
when inside asynchronous pipeline.