3.10 Map

A map is a compound data type with a variable number of key-value associations:

  1. #{Key1=>Value1,...,KeyN=>ValueN}

Each key-value association in the map is called anassociation pair. The key and value parts of the pair arecalled elements. The number of association pairs is said to be the size of the map.

There exists a number of BIFs to manipulate maps.

Examples:

  1. 1> M1 = #{name=>adam,age=>24,date=>{july,29}}.
  2. #{age => 24,date => {july,29},name => adam}
  3. 2> maps:get(name,M1).
  4. adam
  5. 3> maps:get(date,M1).
  6. {july,29}
  7. 4> M2 = maps:update(age,25,M1).
  8. #{age => 25,date => {july,29},name => adam}
  9. 5> map_size(M).
  10. 3
  11. 6> map_size(#{}).
  12. 0

A collection of maps processing functions can be found in maps manual page in STDLIB.

Read more about maps in Map Expressions.

Note

Maps are considered to be experimental during Erlang/OTP R17.