A Functional, Type-level solution to the problem described in the root project's README.
ADTs to represent data; State transitions and behaviours as referentially transparent functions; Phantom Types to constraint the inputs as well as the outputs for each transition.
- Even easier to reason about and test due to referential transparency;
- Catches illegal state transition attempts at compile time;
- Concise without compromising safety or expressiveness.
- Adds additional type checking requirements upstream;
- Referentially transparency for state management may prove confusing for people who are more used to mutable state.
Compile time safety at the Service boundaries push runtime checks upstream.
- Non-binary transitions are cumbersome to represent in languages without support for union types.
Currently, best bet for Scala 2 programs is subtyping which can get unwindly pretty fast (see Scala 2 solution).
In Scala 3, Union types are a more suitable language feature for representing such transitions (see Scala 3 solution).
The code is distributed under the GNU GPLv3 license (see COPYING). The choice of GPLv3 is to enforce sharing of improvements to the examples.
The supporting documentation is distributed under the Attribution-ShareAlike Creative Commons License (CC BY-SA).

