crem-0.1.0.0: Compositional representable executable machines
Safe HaskellSafe-Inferred
LanguageGHC2021

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

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 decide function, which says how to compute the output out of the input and the current state
  • an evolve function, which allows us to specify the next state from the current state and the output

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.