Table of Contents

Interface IAlgebra<TEvent, TState>

Namespace
Virtufin.Core.Behaviour
Assembly
Virtufin.Core.dll

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

TEvent

The event type consumed.

TState

The 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

state TState

Current state.

evt TEvent

Event to apply.

Returns

TState

Next state.