Intro

Maps are used to store key/value pairs. Maps are defined with curly brackets prefixed with a percent %{} .

elixir
# Define a map

map = %{stuff: "stuff", things: "things"}

# Define a map with the hash rocket syntax

map = %{:stuff => "stuff", :things => "things"}

# Create a map from a list of tuples

map = Map.new([{:stuff, "stuff"}, {:things, "things"}])

Considerations

  • It is convention to use atoms as keys for maps.
  • When an atom is used for a key the value can be retrieved with the . syntax. IE: map.stuff
# elixir