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

Function min

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

Source from the content-addressed store, hash-verified

226 valueExtractor: (value: T) => V,
227): AggregateFunction<T, V | undefined, V | undefined>
228export function min<T, V extends CanMinMax>(
229 valueExtractor?: (value: T) => V,
230): AggregateFunction<T, V | undefined, V | undefined> {
231 const extractor = valueExtractor ?? ((v: T) => v as unknown as V)
232 return {
233 preMap: (data: T) => extractor(data),
234 reduce: (values) => {
235 let minValue: V | undefined
236 for (const [value, _multiplicity] of values) {
237 if (!minValue || (value && value < minValue)) {
238 minValue = value
239 }
240 }
241 return minValue
242 },
243 }
244}
245
246/**
247 * Creates a max aggregate function that computes the maximum value in a group

Callers 1

groupBy.test.tsFile · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected