Skip to main content

Sum

Reducer to maintain the sum of input values.

A Reducer that maintains the sum of values as they are added and removed from a collection.

Implements

  • NativeStub
  • Reducer<number, number>

Constructors

new Sum()

new Sum(): Sum

Returns

Sum

Properties

[sknative]

[sknative]: string;

Implementation of

NativeStub.[sknative]

add()

add: (accum) => number;

Include a new value into the accumulated value.

Parameters

ParameterTypeDescription
accumnumberThe current accumulated value; null only if initial is null and value is the first to be added.

Returns

number

The updated accumulated value.

Implementation of

Reducer.add

initial

initial: number;

Initial accumulated value, providing the accumulated value for keys that are not associated to any values.

Implementation of

Reducer.initial

remove()

remove: (accum) => Nullable<number>;

Exclude a previously added value from the accumulated value.

It is always valid for remove to return null, in which case the correct accumulated value will be computed using initial and add on each of the key's values.

WARNING: If remove returns a non-null value, then it must be equal to calling add on each of the values associated to the key, starting from initial. That is, accum, add(remove(accum, value), value), and remove(add(accum, value), value) must all be equal for any accum and value unless both the mentioned remove calls return null.

Parameters

ParameterTypeDescription
accumnumberThe current accumulated value.

Returns

Nullable<number>

The updated accumulated value, or null indicating that the accumulated value should be recomputed using add and initial.

Implementation of

Reducer.remove