nustack

Cardinality

The second main dimension. Where mutation asks does this touch Context, cardinality asks how many values does it yield.

Definition

Each atom yields in one of three shapes:

  • SCALAR - one value.
  • STREAM - 0..N values.
  • VOID - nothing.

Plus one polymorphic case:

  • TRANSPARENT - forwards whatever the child yields (Span).

What this forces

Yielding kinds split by cardinality:

  • Query -> ScalarQuery (one value) or StreamQuery (many).
  • Action -> ScalarAction (one value) or StreamAction (many).

Refs are SCALAR (one address, one value). Commands and Flows are VOID (no yield, so the split doesn't apply). Span is TRANSPARENT (forwards its body).

Consequence

A scalar consumer can't honestly accept a stream producer - there's no canonical reduction (first? last? sum? collect?). The choice belongs to the consumer, named explicitly: a reduction.

Reduction

Cardinality is what an atom yields. Reduction is what one slot takes: a consumer names one reduction slot that takes a stream; its other slots take one value.

A slot role, not a kind. Any kind yielding one value or nothing can reduce, keeping its own mutation and yield:

ReductionKindExample
QueryReductionScalarQueryFirst, Collect, Reduce(op, init)
ActionReductionScalarActionPutStream(store, stream) -> id
CommandReductionCommandAppendAll(list_ref, stream)

An ActionReduction is one write fed many values - the input-side twin of StreamAction's one write yielding many (INSERT ... SELECT vs DELETE ... RETURNING). N separate writes would lose the same atomicity.

Laws:

  • a stream child outside a reduction slot is refused;
  • a reduction slot holding a scalar is refused.

Stream consumers (StreamQuery, StreamAction), Flows and Spans are outside: they take streams on their own terms.

On this page