June 2022
Intermediate to advanced
130 pages
2h 45m
English
When you want to model sequential data in Elixir, you have two choices, tuples and lists. We’ve already covered tuples. Tuples are great for short sequences of data with a fixed length, while lists can hold potentially longer sequences of data with variable lengths. While the same tuple has data that might vary in type, lists tend to hold items of the same type, but not always.
Along with maps, lists are among the most important Elixir data structures. Let’s do our usual exploration in the console:
| | iex(1)> [1, 2, 3] |
| | [1, 2, 3] |
Elixir syntax represents lists in square brackets. Let’s inspect the type. We’ll look at the results in pieces:
| | iex(2)> i |
| | Term |
| | [1, 2, 3] |
| | Data type |
| | List |
The term we typed is a list, and the module associated ...
Read now
Unlock full access