MCPcopy Index your code
hub / github.com/tinyplex/tinybase / getAggregateValue

Function getAggregateValue

src/common/aggregators.ts:76–118  ·  view source on GitHub ↗
(
  aggregateValue: AggregateValue | undefined,
  oldLength: number,
  newValues: IdMap<Value | undefined>,
  changedValues: Coll<[Value | undefined, Value | undefined]>,
  aggregators: Aggregators<Value, AggregateValue>,
  force = false,
)

Source from the content-addressed store, hash-verified

74 ]);
75
76export const getAggregateValue = <Value, AggregateValue>(
77 aggregateValue: AggregateValue | undefined,
78 oldLength: number,
79 newValues: IdMap<Value | undefined>,
80 changedValues: Coll<[Value | undefined, Value | undefined]>,
81 aggregators: Aggregators<Value, AggregateValue>,
82 force = false,
83) => {
84 if (collIsEmpty(newValues)) {
85 return undefined;
86 }
87
88 const [aggregate, aggregateAdd, aggregateRemove, aggregateReplace] =
89 aggregators;
90 force ||= isUndefined(aggregateValue);
91 collForEach(changedValues, ([oldValue, newValue]) => {
92 if (!force) {
93 aggregateValue = isUndefined(oldValue)
94 ? aggregateAdd?.(
95 aggregateValue as AggregateValue,
96 newValue as Value,
97 oldLength++,
98 )
99 : isUndefined(newValue)
100 ? aggregateRemove?.(
101 aggregateValue as AggregateValue,
102 oldValue,
103 oldLength--,
104 )
105 : aggregateReplace?.(
106 aggregateValue as AggregateValue,
107 newValue,
108 oldValue,
109 oldLength,
110 );
111 force ||= isUndefined(aggregateValue);
112 }
113 });
114
115 return force
116 ? aggregate(collValues(newValues) as Value[], collSize(newValues))
117 : aggregateValue;
118};

Callers 2

writeGroupRowFunction · 0.90
setMetricDefinitionFunction · 0.90

Calls 5

collIsEmptyFunction · 0.90
isUndefinedFunction · 0.90
collForEachFunction · 0.90
collValuesFunction · 0.90
collSizeFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…