MCPcopy Create free account
hub / github.com/TanStack/db / max

Function max

packages/db-ivm/src/operators/groupBy.ts:258–274  ·  view source on GitHub ↗
(
  valueExtractor?: (value: T) => V,
)

Source from the content-addressed store, hash-verified

256 valueExtractor: (value: T) => V,
257): AggregateFunction<T, V | undefined, V | undefined>
258export function max<T, V extends CanMinMax>(
259 valueExtractor?: (value: T) => V,
260): AggregateFunction<T, V | undefined, V | undefined> {
261 const extractor = valueExtractor ?? ((v: T) => v as unknown as V)
262 return {
263 preMap: (data: T) => extractor(data),
264 reduce: (values) => {
265 let maxValue: V | undefined
266 for (const [value, _multiplicity] of values) {
267 if (!maxValue || (value && value > maxValue)) {
268 maxValue = value
269 }
270 }
271 return maxValue
272 },
273 }
274}
275
276/**
277 * Creates a median aggregate function that computes the middle value in a sorted group

Callers 1

groupBy.test.tsFile · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected