Interface IAlgebra<TEvent, TState>
An F-algebra over an event log. Given a current state and an event, produce the next state. Combined with the initial state and an event log, the algebra defines a derived signal via the fold (or scan for running computation).
public interface IAlgebra<TEvent, TState> where TEvent : notnull
Type Parameters
TEventThe event type consumed.
TStateThe state type produced.
Examples
public sealed record PositionState(Symbol Symbol, Amount Qty, Price AvgEntry, DateTimeOffset EventTime)
{
public PositionState Apply(IPositionEvent evt) => evt switch
{
PositionEvent.Opened o => new PositionState(o.Symbol, o.Qty, o.Price, o.EventTime),
PositionEvent.Updated u => new PositionState(...),
_ => this,
};
}
Properties
Initial
The empty-state initial value.
TState Initial { get; }
Property Value
- TState
Methods
Apply(TState, TEvent)
Combine current state with an event to produce the next state.
TState Apply(TState state, TEvent evt)
Parameters
stateTStateCurrent state.
evtTEventEvent to apply.
Returns
- TState
Next state.