A map associates keys with values, allowing any term as either side. It supports dynamically sized key-value data and compact structures representing named fields. section 2.4.6
Use maps according to the failure behavior and update operation required:
- Create maps with %{}, map literals, or Map.new/1 from two-element tuples. section 2.4.6
- Read with brackets or Map.get/3; use Map.fetch/2 to distinguish a missing key from a stored value such as :not_found. section 2.4.6
- Choose Map.fetch!/2 when absence should raise, and Map.put/3, Map.update/4, or Map.delete/2 for changes. section 2.4.6
- Use dot access and update syntax for known fields; updating a nonexistent field raises a KeyError. section 2.4.6
Squares and named fields
A squares map can associate integer keys with values: %{1 => 1, 2 => 4, 3 => 9}. Map.put(squares, 4, 16) returns a map containing the new pair. A named-field map such as %{name: "Bob", age: 25} supports bob.age and %{bob | age: 26}. section 2.4.6









































