TinyBase logoTinyBase

AggregateReplace

The AggregateReplace type describes a function that can be used to optimize a custom Aggregate by providing a shortcut for when a single value in the input values is replaced with another.

(
  current: Cell,
  add: Cell,
  remove: Cell,
  length: number,
): ResultCellOrUndefined
TypeDescription
currentCell

The current value of the aggregation.

addCell

The Cell value being added to the aggregation.

removeCell

The Cell value being removed from the aggregation.

lengthnumber

The length of the array of Cell values in the aggregation.

returnsResultCellOrUndefined

Some aggregation functions do not need to recalculate the aggregation of the whole set when one value changes. For example, when replacing a number in a series, the new sum of the series is the previous sum, plus the new value, minus the old value.

If it is not possible to shortcut the aggregation based on just one value changing, return undefined and the aggregation will be completely recalculated.

When possible, if you are providing a custom Aggregate, seek an implementation of an AggregateReplace function that can reduce the complexity cost of changing the input data set in place.

Since

v2.0.0