Function aggregate

  • 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';

    const input = [7, 4, 3, 8, 2, 1]; // unsorted list

    const i = 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.

    Type Parameters

    • T

    • R

    Parameters

    • cb: ((arr) => R | Promise<R>)
        • (arr): R | Promise<R>
        • Parameters

          • arr: T[]

          Returns R | Promise<R>

    Returns Operation<T, R>