| Safe Haskell | Safe-Inferred |
|---|---|
| Language | GHC2021 |
Crem.Decider
Description
The Decider pattern allows to easily describe an aggregate in functional terms
In terms of Mealy machines, a Decider is a machine where the next state is
computed from the previous state and the output
Synopsis
- data Decider (topology :: Topology vertex) input output = forall state.Decider {
- deciderInitialState :: InitialState state
- decide :: forall vertex'. input -> state vertex' -> output
- evolve :: forall initialVertex. state initialVertex -> output -> EvolutionResult topology state initialVertex output
- data EvolutionResult (topology :: Topology vertex) (state :: vertex -> Type) (initialVertex :: vertex) output where
- EvolutionResult :: AllowedTransition topology initialVertex finalVertex => state finalVertex -> EvolutionResult topology state initialVertex output
- deciderMachine :: Decider topology input output -> BaseMachine topology input output
- rebuildDecider :: [output] -> Decider topology input output -> Decider topology input output
Documentation
data Decider (topology :: Topology vertex) input output Source #
A Decider topology input output is a Decider which receives inputs of
type input and emits outputs of type output, where allowed transitions
are constrained by the provided topology.
Being used to describe the domain logic of an aggregate, a Decider is
always pure.
It is defined by:
- its
deciderInitialState - a
decidefunction, which says how to compute theoutputout of theinputand the current state - an
evolvefunction, which allows us to specify the next state from the current state and theoutput
Constructors
| forall state. Decider | |
Fields
| |
data EvolutionResult (topology :: Topology vertex) (state :: vertex -> Type) (initialVertex :: vertex) output where Source #
A smart wrapper over the machine state, which allows to enforce that only
transitions allowed by the topology are actually performed.
Constructors
| EvolutionResult :: AllowedTransition topology initialVertex finalVertex => state finalVertex -> EvolutionResult topology state initialVertex output |
deciderMachine :: Decider topology input output -> BaseMachine topology input output Source #
translate a Decider into a BaseMachine
rebuildDecider :: [output] -> Decider topology input output -> Decider topology input output Source #
rebuild a Decider from a list of outputs
This is the main selling point of a Decider over a generic StateMachine,
since it allows rebuilding a machine from its outputs.