O'Reilly logo

Functional Web Development with Elixir, OTP, and Phoenix by Lance Halvorsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Working Through the States

With the catchall in place, all we need to do from now on is define the positive cases. We’ll add a new clause of check/2 for each new state/event pair that we want to add to the whitelist. By the end of this section, we will have a complete state machine that will describe all the rules of Islands.

Let’s start with the first state, :initialized.

Initialized

When we’re in :initialized, the only permissible action is adding the second player. We’re going to focus on that one action and the transition it triggers, from :initialized to :players_set.

images/state_machine/initialized-players_set.png

We’ll need a clause of check/2 for this that adds this combination of state ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required