Count<T>
Reducer
to maintain the count of input values.
A Reducer
that maintains the number of values as they are added and removed from a collection.
Type Parameters
Type Parameter |
---|
T extends Json |
Implements
Reducer
<T
,number
>NativeStub
Constructors
new Count()
new Count<T>(): Count<T>
Returns
Count
<T
>
Properties
[sknative]
[sknative]: string;
Implementation of
NativeStub.[sknative]
add()
add: (accum) => number;
Include a new value into the accumulated value.
Parameters
Parameter | Type | Description |
---|---|---|
accum | number | The 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
Parameter | Type | Description |
---|---|---|
accum | number | The 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