public <I extends> GearsBuilder<I> accumulate(
    gears.operations.AccumulateOperation<T,I> accumulator)

public <I extends> GearsBuilder<I> accumulate(
    I initialValue, 
    gears.operations.AccumulateOperation<T,I> accumulator)

Accumulate is a many-to-one function that iterates through the records in the pipe and reduces them to a single record.

You can provide a parameter to set the initial accumulator value. Otherwise, the initial accumulator object is null.


Type parameters:

Name Description
I The template type of the returned builder

Function parameters:

Name Type Description
accumulator AccumulateOperation<T,​I> A function with logic to update the accumulator value with each record
initialValue template type I The initial value of the accumulated object


Returns a GearsBuilder object with a new template type.


Both of the following examples count the number of records in the pipeline.

Without the initialValue parameter:

GearsBuilder.CreateGearsBuilder(reader).accumulate((a, r)->{
    Integer ret = null;
    if (a == null) {
	    ret = 1;
    } else {
	    ret = (Integer)a;
    return ret + 1;

With the initialValue parameter set to 0:

GearsBuilder.CreateGearsBuilder(reader).accumulate(0, (a, r)->{
   	return a + 1;