Coming from an object-oriented background I am writing a scrabble clone in elixir/phoenix in order to learn elixir and functional programming.
So my instinct is to have a state map like so:
game_state = {
players: [
{
name: "Bob",
rack: ["A"],
score: 3
},
{
name: "Alice",
rack: ["B"],
score: 10
}
],
board: [
%Tile{
letter: "A",
row: 0,
column: -1
},
%Tile{
letter: "T",
row: 0,
column: 0
}
],
bag: [
"A",
"A",
" "
]
}
This is enough to maintain the state of the game.
Doing it this way seems to give flexiblity, storage and atomicity.
Writing interactions with this state feel a bit awkward and I am thinking I am stuck in OO world and I am building an object rather being functional.
I am thinking modules for bag, players and board.
new_game_state = game_state |> Players.add_player("Fred")
Am I going the wrong way with this?
I am doing things like if Enum.member?(player_state, &(&1.name == name)) do which is hauntingly familiar.
Martin






















