Search⌘ K

Module and Functions

Explore how to build a state machine in Elixir by defining modules and functions that represent and transition state using structs. Learn to implement catchall clauses to handle errors and maintain consistent state during game progression.

Start with a catchall clause

Our goal is to build a whitelist, but we still need to account for all the error cases that won’t match it. A catchall clause helps with this. Therefore, we will define a catchall clause in this section.

Let’s start with a new file at lib/islands_engine/rules.ex. We define the IslandsEngine.Rules module in it and alias it as well:

defmodule IslandsEngine.Rules do
  alias __MODULE__
end

We’ll need to ...