Collector<T, A, R> constructor

const Collector<T, A, R>({
  1. required A supplier(),
  2. required void accumulator(
    1. A,
    2. T
    ),
  3. required A combiner(
    1. A,
    2. A
    ),
  4. required R finisher(
    1. A
    ),
})

Creates a new Collector with the specified functions.

A mutable reduction operation that accumulates input elements into a mutable result container, optionally transforming the accumulated result into a final representation after all input elements have been processed.

Reduction operations can be performed either sequentially or in parallel.

Examples of mutable reduction operations include: accumulating elements into a List; concatenating strings using a StringBuffer; computing summary information about elements such as sum, min, max, or average; computing "pivot table" summaries such as "maximum valued transaction by seller", etc.

Example

final collector = Collector<String, StringBuffer, String>(
  supplier: () => StringBuffer(),
  accumulator: (buffer, element) => buffer.write(element),
  combiner: (buffer1, buffer2) => buffer1..write(buffer2.toString()),
  finisher: (buffer) => buffer.toString(),
);

Implementation

const Collector({
  required this.supplier,
  required this.accumulator,
  required this.combiner,
  required this.finisher,
});