June 2022
Intermediate to advanced
130 pages
2h 45m
English
The first way to represent key-value data in Elixir is to use a combination of the data types we’ve seen so far. To do so, let’s think about the data structures we know about and how to use them.
Remember, tuples hold fixed-length data, where the position of the tuple determines how we treat it. Let’s represent a single key-value pair with a tuple. We’ll create atoms with a number’s name as the key, and the number itself as the value, like this:
| | iex> one = {:one, 1} |
| | {:one, 1} |
| | iex> two = {:two, 2} |
| | {:two, 2} |
| | iex> three = {:three, 3} |
| | {:three, 3} |
That’s a good start. We have a few key-value pairs. That’s not going to get us too far, though. We need to group the data together. Let’s use the only data structure ...
Read now
Unlock full access