Search⌘ K

A Different Path

Learn to design and implement a purely functional state machine in Elixir to manage complex application states and transitions. This lesson helps you understand the benefits of separating state logic from business logic, improving code clarity and maintainability. Discover how state machines model events and enforce rules within a system, preparing you to translate these concepts into executable code.

Functional state machine

You might think we could make decisions about the application stages, stage transitions, and events with conditional logic. You would be right, but the costs would be high. The number of nested if statements necessary to do the job would lead to a snarl of code paths. We would face real readability and maintainability problems.

Therefore, we’re going to choose a different direction. We’ll implement our own purely functional state machine to handle all the stages that Islands will go through in the course of a full game. It’s going to make decisions for the application about which actions to allow and which to deny at a given stage. It will manage transitions ...