I am learning elm and need some guidance around decoding and types?
I’m creating a little multiplayer game that uses web sockets. When one player makes a move, the new game state is broadcast to all players. The game has a variety of round types like “normal_round”, “power_play_round”, “sudden_death_round”. I am currently decoding this as a String and doing lots of comparisons based on this e.g.
case model.round of
"normal_round" -> ...
"power_play_round" -> ...
I feel this is somewhat incorrect/bad pattern, like magic strings.
Would a better approach be a custom type? Something like:
type GameRound = Normal | PowerPlay | SuddenDeath
type alias Model = {
round : Maybe GameRound
...
}
My concern here is that I don’t really know what the Nothing means in this case.
Keep strings or custom type? Any guidance is most welcome.