https://github.com/perty/elm-impossible-state-transition
https://github.com/perty/elm-impossible-state-transition
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/perty/elm-impossible-state-transition
- Owner: perty
- Created: 2019-05-09T09:15:06.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-10T09:46:38.000Z (over 3 years ago)
- Last Synced: 2025-01-18T18:40:25.037Z (over 1 year ago)
- Language: HTML
- Size: 23.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# Make impossible state transitions impossible
In any sane language you can make impossible state impossible by correct modelling and catch mistakes at compile time already.
But what about state _transitions_? And in compile time? We had a discussion at Oslo Elm conference 2019. Then I wrote a suggested solution and posted it here [https://discourse.elm-lang.org/t/making-impossible-state-transitions-impossible-oslo-elm-day-question/3159](https://discourse.elm-lang.org/t/making-impossible-state-transitions-impossible-oslo-elm-day-question/3159).
Here you find a model of an order tracking system. An order goes through different states but not all transitions are possible. The proof is in that `Main.elm` do not compile as it tries to break the rules of the state machine.
```mermaid
stateDiagram-v2
[*] --> Initial : init
Initial --> Processing : process
Initial --> Cancelled : cancelInital
Processing --> Cancelled : cancelProcessing
Processing --> Shipping: ship
Shipping --> Shipped : shipped
Shipping --> Lost : loose
Lost --> [*]
Shipped --> [*]
```
This repository keeps the code. And 2023 I believe I should write a Readme too!