Search⌘ K
AI Features

A Different Approach

Explore how representing data with lists of lists or maps affects ease of access and updates in Elixir projects. Understand why structuring data with your access patterns in mind leads to cleaner, more maintainable code in functional programming.

Making the board using a list of strings

What if we make one small change by representing the board as a list of lists of strings? Here are the commands for accessing and inserting elements:

Executable

C++
board = [ ["O", " ", " "],
[" ", "X", " "],
[" ", " ", " "] ]
C++
get_in(board, [Access.at(1), Access.at(1)])
C++
board = [ ["O", " ", " "],
[" ", "X", " "],
[" ", " ", " "] ]

Output

iex(1)> board = [ ["O", " ", " "],
...(1)> [" ", "X", " "],
...(1)> [" ", " ", " "] ]
[["O", " ", " "], [" ", "X", " "], [" ", " ", " "]]
iex(2)>
...