Keywords, maps, and dictionaries
However, we should take a quick moment to introduce more collections. We have covered lists and tuples as either linked lists or contiguous blocks of memory similar to arrays, respectively. However, there is another set of types we haven't covered—associative data structures.
Elixir has a few different kinds of associate, key-value structures, keywords, and maps. Both are a type of dictionary, or hash table, although, they have different underlying implementations and performance characteristics.
Keywords
Keywords are a special name for a list of 2-tuples, or pairs, where the first element of each pair, the key, is an atom. For example, we could see the following list:
iex(1)> alist = [{:a, 0}, {:b, 2}] [a: 0, b: 2] iex(2)> alist == [a: 0, b: 2] true iex(3)> alist[:a] 0
That is, a list of pairs is the same as a flat list of alternating atoms and values.
There are some very important properties of keywords that make them special and useful:
Keys must be...