December 2019
Intermediate to advanced
248 pages
5h 34m
English
One of the most important data structures in Elixir is the list. If you’re thinking about skipping this section because lists are arrays, please stop and read on. In Elixir, lists are singly linked, meaning that each node of a list points to the next node. That’s extremely different than arrays. Arrays make random access cheap, but traversing lists takes longer.
Here’s the main point. In Elixir, a list with n elements is actually n different lists. Said another way, you can accurately represent [1, 2, 3] with a list construction operator, called cons cells, like this:
| | [ 1 | |
| | [ 2 | |
| | [ 3 | [] ] ] ] |
We have four different lists. Each list starts with an open bracket and any code can bind to any one of those individual lists. Each |
Read now
Unlock full access