Metakit / @doeixd/metakit/relation

reduce

function · packages/metakit/src/relation.ts:303

function reduce<
  O extends RowInput,
  Row,
  Op extends CommutativeMonoid,
  V extends ExprInput<
    never,
    Schema.Schema.Type<Op['descriptor']['result']> | null
  >,
  R extends Test = true,
>(
  of: O,
  relation: Relation<Row>,
  op: Op,
  value: (each: Each<Row>) => V,
  test?: (each: Each<Row>) => R,
): Expr<
  EnvOfInput<O> & EnvOfInput<V> & EnvOfInput<R>,
  Schema.Schema.Type<Op['descriptor']['result']> | NullOf<O>
>

Fold value over the rows pointing at of that pass test using a declared commutative-monoid operation op: returns op's identity over no rows and skips null contributions.