April 2024
Beginner to intermediate
224 pages
5h 7m
English
Maps are the most important data type in your Elixir toolbox. A map consists of key-value pairs, where the key and value can be any data type. In practice, you’ll use maps to hold and pass around all of the data in your application.
Maps are created with the %{} syntax. You can create an empty map or set the initial key-value pairs in the map. Try it out in IEx:
| | $ iex |
| | iex> empty = %{} |
| | %{} |
| | |
| | iex> populated = %{key: "value", another: "entry"} |
| | %{another: "entry", key: "value"} |
| | |
| | iex> Map.get(populated, :another) |
| | "entry" |
| | |
| | iex> populated[:another] |
| | "entry" |
| | |
| | iex> populated.another |
| | "entry" |
You’ll notice that the second map came out in a different order ...
Read now
Unlock full access