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"
当前内容版权归 hamler-lang 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 hamler-lang .