View Source mapz (mapz v2.3.0)
Link to this section Summary
Types
An iterator representing the associations in a map with keys of type Key and values of type Value.
Functions
Returns a tuple {ok,Value}, where Value is the value associated with Path, or error if no value is associated with Path in Map.
Returns value Value associated with Path if Map contains Path.
Returns value Value associated with Path if Map contains Path. If no value is associated with Path, Default is returned.
Returns a map iterator Iterator that can be used by deep_next/1 to recursively traverse the path-value associations in a deep map structure.
Equivalent to deep_merge(fun (_, V) -> V end, #{}, Maps).
Equivalent to deep_merge([Map1, Map2]).
Merges a list of maps Maps recursively into a single map Target. If a path exist in several maps, the function Fun is called with the previous and the conflicting value to resolve the conflict. The return value from the function is put into the resulting map.
Merges a list of maps Maps recursively into a single map. If a path exist in several maps, the function Fun is called with the path, the previous and the conflicting value to resolve the conflict. The return value from the function is put into the resulting map.
Merges a list of maps Maps recursively into a single map. If a path exist in several maps, the function Fun is called with the path, the previous and the conflicting value to resolve the conflict. The return value from the function is put into the resulting map.
Returns the next path-value association in Iterator and a new iterator for the remaining associations in the iterator.
Associates Path with value Value and inserts the association into map Map2. If path Path already exists in map Map1, the old associated value is replaced by value Value. The function returns a new map Map2 containing the new association and the old associations in Map1.
Removes the last existing key of Path, and its associated value from Map1 and returns a new map Map2 without that key. Any deeper non-existing keys are ignored.
Returns a tuple {ok,Value} where Value is the value associated with Path, or {error, PartialPath, Value} if no value is associated with Path in Map, where PartialPath represents the path to the last found element in Map and Value is the value found at that path.
If Path exists in Map1, the old associated value is replaced by value Value. The function returns a new map Map2 containing the new associated value.
Update a value in a Map1 associated with Path by calling Fun on the old value to get a new value.
Update a value in a Map1 associated with Path by calling Fun on the old value to get a new value. If Path is not present in Map1 then Init will be associated with Path.
Equivalent to inverse(Map, fun (V, _) -> V end).
Inverts a map by inserting each value as the key with its corresponding key as the value. If two keys have the same value in Map, Fun is called with the old and new key to determine the resulting value.
Link to this section Types
-type combiner() :: fun((Path :: path(), Old :: term(), New :: term()) -> term()).
-opaque iterator()
An iterator representing the associations in a map with keys of type Key and values of type Value.
Created using deep_iterator/1.
deep_next/1.
-type path() :: [term()].
Link to this section Functions
-spec deep_find(path(), map()) -> {ok, term()} | error.
Returns a tuple {ok,Value}, where Value is the value associated with Path, or error if no value is associated with Path in Map.
{badmap,Map}ifMapis not a map{badpath,Path}ifPathis not a path
-spec deep_get(path(), map()) -> term().
Returns value Value associated with Path if Map contains Path.
{badmap,Map}ifMapis not a map{badpath,Path}ifPathis not a path{badvalue,P}if a term that is not a map exists as a intermediate key at the pathP{badkey,Path}if no value is associated with pathPath
-spec deep_get(path(), map(), term()) -> term().
Returns value Value associated with Path if Map contains Path. If no value is associated with Path, Default is returned.
{badmap,Map}ifMapis not a map{badpath,Path}ifPathis not a path{badvalue,P}if a term that is not a map exists as a intermediate key at the pathP
-spec deep_iterator(map()) -> iterator().
Returns a map iterator Iterator that can be used by deep_next/1 to recursively traverse the path-value associations in a deep map structure.
{badmap,Map} exception if Map is not a map.
-spec deep_merge([map()]) -> map().
Equivalent to deep_merge(fun (_, V) -> V end, #{}, Maps).
Merges a list of maps recursively into a single map. If a path exist in several maps, the value in the first nested map is superseded by the value in a following nested map.
The call can raise the following exceptions:{badmap,Map}exception if any of the maps is not a map
-spec deep_merge(map(), map()) -> map().
Equivalent to deep_merge([Map1, Map2]).
-spec deep_merge(fun((Old :: term(), New :: term()) -> term()), map(), map() | [map()]) -> map().
Merges a list of maps Maps recursively into a single map Target. If a path exist in several maps, the function Fun is called with the previous and the conflicting value to resolve the conflict. The return value from the function is put into the resulting map.
{badmap,Map}exception if any of the maps is not a map
-spec deep_merge_with(Fun :: combiner(), Maps :: [map()]) -> map().
Merges a list of maps Maps recursively into a single map. If a path exist in several maps, the function Fun is called with the path, the previous and the conflicting value to resolve the conflict. The return value from the function is put into the resulting map.
{badmap,Map}exception if any of the maps is not a map
-spec deep_merge_with(Fun :: combiner(), Map1 :: map(), Map2 :: map()) -> map().
Merges a list of maps Maps recursively into a single map. If a path exist in several maps, the function Fun is called with the path, the previous and the conflicting value to resolve the conflict. The return value from the function is put into the resulting map.
{badmap,Map}exception if any of the maps is not a map
Returns the next path-value association in Iterator and a new iterator for the remaining associations in the iterator.
If the value is another map the iterator will first return the map as a value with its path. Only on the next call the inner value with its path is returned. That is, first {Path, map(), iterator()} and then {InnerPath, Value, iterator()}.
none is returned.
-spec deep_put(path(), term(), map()) -> map().
Associates Path with value Value and inserts the association into map Map2. If path Path already exists in map Map1, the old associated value is replaced by value Value. The function returns a new map Map2 containing the new association and the old associations in Map1.
{badmap,Map}ifMap1is not a map{badpath,Path}ifPathis not a path{badvalue,P}if a term that is not a map exists as a intermediate key at the pathP
-spec deep_remove(path(), map()) -> map().
Removes the last existing key of Path, and its associated value from Map1 and returns a new map Map2 without that key. Any deeper non-existing keys are ignored.
{badmap,Map}ifMapis not a map{badpath,Path}ifPathis not a path
Returns a tuple {ok,Value} where Value is the value associated with Path, or {error, PartialPath, Value} if no value is associated with Path in Map, where PartialPath represents the path to the last found element in Map and Value is the value found at that path.
When no key in Path exists in Map, {error, [], Map} is returned.
{badmap,Map}ifMapis not a map{badpath,Path}ifPathis not a path
-spec deep_update(path(), term(), map()) -> map().
If Path exists in Map1, the old associated value is replaced by value Value. The function returns a new map Map2 containing the new associated value.
{badmap,Map}ifMap1is not a map{badpath,Path}ifPathis not a path{badvalue,P}if a term that is not a map exists as a intermediate key at the pathP{badkey,Path}if no value is associated with pathPath
-spec deep_update_with(path(), fun((term()) -> term()), map()) -> map().
Update a value in a Map1 associated with Path by calling Fun on the old value to get a new value.
{badmap,Map}ifMap1is not a map{badpath,Path}ifPathis not a path{badvalue,P}if a term that is not a map exists as a intermediate key at the pathP{badkey,Path}if no value is associated with pathPathbadargifFunis not a function of arity 1
-spec deep_update_with(path(), fun((term()) -> term()), any(), map()) -> map().
Update a value in a Map1 associated with Path by calling Fun on the old value to get a new value. If Path is not present in Map1 then Init will be associated with Path.
{badmap,Map}ifMap1is not a map{badpath,Path}ifPathis not a path{badvalue,P}if a term that is not a map exists as a intermediate key at the pathPbadargifFunis not a function of arity 1
-spec inverse(map()) -> map().
Equivalent to inverse(Map, fun (V, _) -> V end).
Inverts a map by inserting each value as the key with its corresponding key as the value. If two keys have the same value, the value for the first key in map order will take precedence.
The call can raise the following exceptions:{badmap,Map}ifMapis not a map
-spec inverse(map(), fun((Old :: term(), New :: term()) -> term())) -> map().
Inverts a map by inserting each value as the key with its corresponding key as the value. If two keys have the same value in Map, Fun is called with the old and new key to determine the resulting value.
{badmap,Map}ifMapis not a mapbadargifFunis not a function of arity 2