This module contains functions for maps processing.
Returns a tuple
Example:
> Map = #{"hi" => 42},
Key = "hi",
maps:find(Key,Map).
{ok,42}
Calls
Example:
> Fun = fun(K,V,AccIn) when is_list(K) -> AccIn + V end,
Map = #{"k1" => 1, "k2" => 2, "k3" => 3},
maps:fold(Fun,0,Map).
6
The function takes a list of key-value tuples elements and builds a map. The associations may be in any order and both keys and values in the association may be of any term. If the same key appears more than once, the latter (rightmost) value is used and the previous values are ignored.
Example:
> List = [{"a",ignored},{1337,"value two"},{42,value_three},{"a",1}],
maps:from_list(List).
#{42 => value_three,1337 => "value two","a" => 1}
Returns the value
Example:
> Key = 1337,
Map = #{42 => value_two,1337 => "value one","a" => 1},
maps:get(Key,Map).
"value one"
Returns
Example:
> Map = #{"42" => value}.
#{"42"> => value}
> maps:is_key("42",Map).
true
> maps:is_key(value,Map).
false
Returns a complete list of keys, in arbitrary order, which resides within
Example:
> Map = #{42 => value_three,1337 => "value two","a" => 1},
maps:keys(Map).
[42,1337,"a"]
The function produces a new map
Example:
> Fun = fun(K,V1) when is_list(K) -> V1*2 end,
Map = #{"k1" => 1, "k2" => 2, "k3" => 3},
maps:map(Fun,Map).
#{"k1" => 2,"k2" => 4,"k3" => 6}
Merges two maps into a single map
Example:
> Map1 = #{a => "value_one", b => "value_two"},
Map2 = #{a => 1, c => 2},
maps:merge(Map1,Map2).
#{a => 1,b => "value_two",c => 2}
Returns a new empty map.
Example:
> maps:new().
#{}
Associates
Example:
> Map = #{"a" => 1}.
#{"a" => 1}
> maps:put("a", 42, Map).
#{"a" => 42}
> maps:put("b", 1337, Map).
#{"a" => 1,"b" => 1337}
The function removes the
Example:
> Map = #{"a" => 1}.
#{"a" => 1}
> maps:remove("a",Map).
#{}
> maps:remove("b",Map).
#{"a" => 1}
The function returns the number of key-value associations in the
Example:
> Map = #{42 => value_two,1337 => "value one","a" => 1},
maps:size(Map).
3
The fuction returns a list of pairs representing the key-value associations of
Example:
> Map = #{42 => value_three,1337 => "value two","a" => 1},
maps:to_list(Map).
[{42,value_three},{1337,"value two"},{"a",1}]
If
Example:
> Map = #{"a" => 1}.
#{"a" => 1}
> maps:update("a", 42, Map).
#{"a" => 42}
Returns a complete list of values, in arbitrary order, contained in map
Example:
> Map = #{42 => value_three,1337 => "value two","a" => 1},
maps:values(Map).
[value_three,"value two",1]
Returns a new map
Example:
> Map = #{42 => value_three,1337 => "value two","a" => 1},
Ks = ["a",42,"other key"],
maps:without(Ks,Map).
#{1337 => "value two"}