Collector


Object Hierarchy:

Gpseq.Collector Gpseq.Collector Gpseq.Collector GLib.Object GLib.Object GLib.Object->Gpseq.Collector

Description:


public interface Collector<R,A,G> : Object

An object for mutable reduction operation that accumulates input elements into a mutable accumulator, and transforms it into a final result.

A collector implements four methods: create_accumulator, accumulate, combine, and finish.

  1. create_accumulator() - creates a new accumulator, such as Gee.Collection.
  2. accumulate() - incorporates a new element into a accumulator.
  3. combine() - combines two accumulators into one.
  4. finish() - transforms the accumulator into a final result.

The methods must satisfy an identity and an associativity constraints. The identity constraint means that combining any accumulator with an empty accumulator must produce an equivalent result. i.e. an accumulator a must be equivalent to collector.accumulate(a, collector.create_accumulator())

The associativity constraint means that splitting the computation must produce an equivalent result. i.e.:

// the two computations below must be equivalent.
// collector: a collector
// g0, g1: elements

A a0 = collector.create_accumulator();
collector.accumulate(g0, a0);
collector.accumulate(g1, a0);
A r0 = collector.finish(a0);

A a1 = collector.create_accumulator();
collector.accumulate(g0, a1);
A a2 = collector.create_accumulator();
collector.accumulate(g1, a2);
A r1 = collector.finish( collector.combine(a1, a2) );

Collectors also have a property, features. it provides hints that can be used to optimize the operation.

See also:

Seq.collect, Seq.collect_ordered, Collectors, CollectorFeatures


Namespace: Gpseq
Package: gpseq-1.0

Content:

Properties:

Methods:

Inherited Members:

All known members inherited from class GLib.Object



2022 vala-language.org