The accumulator. Can also be referenced as $$
. Used to store the result of the lambda expression after each iteration of the reduce operation.
The accumulator parameter can be set to an initial value using the
syntax acc = initValue
. In this case, the lambda expression is
called with the first element of the input array. Then the result
is set as the new accumulator value.
If an initial value for the accumulator is not set, the accumulator is set to the first element of the input array. Then the lambda expression is called with the second element of the input array.
The initial value of the accumulator and the lambda expression
dictate the type of result produced by the reduce
function. If
the accumulator is set to acc = {}
, the result is usually of type
Object
. If the accumulator is set to acc = []
, the result
is usually of type Array
. If the accumulator is set to acc = ""
,
the result is usually a String
.