Reducer<V, A>
Reactive function that can be used to accumulate each key's values.
EagerCollection.reduce accepts a constructor function of a top-level class that implements this Reducer interface.
For each key in a collection, a Reducer can compute and maintain an accumulated value of the key's values as associations are added and removed from the collection.
Type Parameters
| Type Parameter | Description |
|---|---|
V extends Json | Type of input values. |
A extends Json | Type of accumulated and output values. |
Methods
add()
add(accum, value): A
Include a new value into the accumulated value.
Parameters
| Parameter | Type | Description |
|---|---|---|
accum | Nullable<A> | The current accumulated value; null only if initial is null and value is the first to be added. |
value | V & DepSafe | The added value. |
Returns
A
The updated accumulated value.
remove()
remove(accum, value): Nullable<A>
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
| Parameter | Type | Description |
|---|---|---|
accum | A | The current accumulated value. |
value | V & DepSafe | The removed value. |
Returns
Nullable<A>
The updated accumulated value, or null indicating that the accumulated value should be recomputed using add and initial.
Properties
initial
initial: Nullable<A>;
Initial accumulated value, providing the accumulated value for keys that are not associated to any values.