Accumulator components aggregate values over time using a reducer function.
Options
:mergeable- Whentrue, indicates this accumulator's reducer has CRDT-like properties (commutative, idempotent, associative) and is safe for parallel merge without ordering guarantees. Defaults tofalse.
Example
# A counter is mergeable (addition is commutative and associative)
accumulator(
init: fn -> 0 end,
reducer: fn value, acc -> acc + value end,
mergeable: true
)
# A list accumulator is NOT mergeable (order matters)
accumulator(
init: fn -> [] end,
reducer: fn value, acc -> [value | acc] end,
mergeable: false
)Runtime Context
Accumulators can reference external runtime values via context/1 in their
reducer function. When detected, the reducer is rewritten to arity-3
(value, acc, meta_ctx) and values are resolved from the workflow's run_context.
Runic.accumulator(0, fn x, state -> state + x * context(:factor) end,
name: :scaled
)Use context/2 to provide defaults:
Runic.accumulator(0, fn x, state -> state + x * context(:factor, default: 1) end,
name: :scaled
)
Summary
Functions
Returns whether this accumulator has meta references (e.g., context/1)
that need to be resolved during the prepare phase.