Map

Map

A set of functions for working with maps.

Maps are the “go to” key-value data structure in Elixir. Maps can be created with the %{} syntax, and key-value pairs can be expressed as key => value:

iex> %{}
%{}
iex> %{"one" => :two, 3 => "four"}
%{3 => "four", "one" => :two}

Key-value pairs in a map do not follow any order (that’s why the printed map in the example above has a different order than the map that was created).

Maps do not impose any restriction on the key type: anything can be a key in a map. As a key-value structure, maps do not allow duplicated keys; keys are compared using the exact-equality operator (===). If colliding keys are defined in a map literal, the last one prevails.

When the key in a key-value pair is an atom, the 登录查看完整内容