Elixir offers many ways to store data in a collection: tuples, lists, keyword lists,
maps and structs. Let's review each of those and discuss use cases.
{:error, 543, "You forgot something"} end case transform(data) do {:error, _code, message} -> "Error: #{message}" {:ok, data} -> data end # "Error: You forgot something"
Associative collection (key/value) 4 Keys are atoms only, ordered and not unique 4 Implements Access behavior (list[key]) 4 Not an Erlang type 4 Special list of 2-term tuples
for passing options to a function ✅ Can use all operations available to lists ! Like a regular list, we cannot pattern match on one element of a list containing multiple elements
on a single element 4 Can use dot notation to access a value if keys are atoms 4 It Implement the access behavior 4 Closest thing to a hash or Dict in other languages
data to a function ✅ Great for pattern matching in function heads ! Unstructured and untyped data store ! No indifferent access (if key is an atom, you cannot access it's value using a string)
of a map ✅ Type checking enforced at compile time ! Be careful when using Map functions, you could end- up with a struct disconnected from its definition