Maps Mapping

Maps Mapping

The syntax of Maps in Hamler is the same as Erlang. The differences are listed below:

  • The keys of a Map must have the same type in Hamler;
  • The values of a Map must have the same type in Hamler;
  • The syntax #{k := v} is only used for map pattern matching.

Maps in Hamler:

-- New map, values and keys must have the same type.
m = #{:foo => "foo", :bar => "bar"}

-- Pattern matching
#{:foo := a, :bar := b} = m
a :: String -- "foo"
b :: String -- "bar"

Maps in Erlang:

%% Create a map
M = #{foo => "foo", bar => "bar"}

%% Pattern matching
#{foo := A, bar := B} = M.
A  %% "foo"
B  %% "bar"