View Source mapz (mapz v2.3.0)

Link to this section Summary

Types

A combiner function that takes a path, and its two conflicting old values and returns a new value.

An iterator representing the associations in a map with keys of type Key and values of type Value.

A list of keys that are used to iterate deeper into a map of maps.

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.

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.

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()).
A combiner function that takes a path, and its two conflicting old values and returns a new value.
-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.

Consumed by deep_next/1.
-type path() :: [term()].
A list of keys that are used to iterate deeper into a map of maps.

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.

The call can raise the following exceptions:
  • {badmap,Map} if Map is not a map
  • {badpath,Path} if Path is not a path
-spec deep_get(path(), map()) -> term().

Returns value Value associated with Path if Map contains Path.

The call can raise the following exceptions:
  • {badmap,Map} if Map is not a map
  • {badpath,Path} if Path is not a path
  • {badvalue,P} if a term that is not a map exists as a intermediate key at the path P
  • {badkey,Path} if no value is associated with path Path
Link to this function

deep_get(Path, Map, Default)

View Source
-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.

The call can raise the following exceptions:
  • {badmap,Map} if Map is not a map
  • {badpath,Path} if Path is not a path
  • {badvalue,P} if a term that is not a map exists as a intermediate key at the path P
-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.

The call fails with a {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]).

Link to this function

deep_merge(Fun, Target, Maps)

View Source
This function is deprecated. Please use the module deep_merge_with/3 instead..
-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.

The call can raise the following exceptions:
  • {badmap,Map} exception if any of the maps is not a map
map.
Link to this function

deep_merge_with(Fun, Maps)

View Source
-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.

The call can raise the following exceptions:
  • {badmap,Map} exception if any of the maps is not a map
map.
Link to this function

deep_merge_with(Fun, Map1, Map2)

View Source
-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.

The call can raise the following exceptions:
  • {badmap,Map} exception if any of the maps is not a map
map.
-spec deep_next(iterator()) -> {path(), term(), iterator()} | none.

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()}.

If there are no more associations in the iterator, none is returned.
Link to this function

deep_put(Path, Value, Map1)

View Source
-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.

The call can raise the following exceptions:
  • {badmap,Map} if Map1 is not a map
  • {badpath,Path} if Path is not a path
  • {badvalue,P} if a term that is not a map exists as a intermediate key at the path P
-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.

The call can raise the following exceptions:
  • {badmap,Map} if Map is not a map
  • {badpath,Path} if Path is 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.

The call can raise the following exceptions:
  • {badmap,Map} if Map is not a map
  • {badpath,Path} if Path is not a path
Link to this function

deep_update(Path, Value, Map1)

View Source
-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.

The call can raise the following exceptions:
  • {badmap,Map} if Map1 is not a map
  • {badpath,Path} if Path is not a path
  • {badvalue,P} if a term that is not a map exists as a intermediate key at the path P
  • {badkey,Path} if no value is associated with path Path
Link to this function

deep_update_with(Path, Fun, Map1)

View Source
-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.

The call can raise the following exceptions:
  • {badmap,Map} if Map1 is not a map
  • {badpath,Path} if Path is not a path
  • {badvalue,P} if a term that is not a map exists as a intermediate key at the path P
  • {badkey,Path} if no value is associated with path Path
  • badarg if Fun is not a function of arity 1
Link to this function

deep_update_with(Path, Fun, Init, Map1)

View Source
-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.

The call can raise the following exceptions:
  • {badmap,Map} if Map1 is not a map
  • {badpath,Path} if Path is not a path
  • {badvalue,P} if a term that is not a map exists as a intermediate key at the path P
  • badarg if Fun is 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} if Map is 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.

The call can raise the following exceptions:
  • {badmap,Map} if Map is not a map
  • badarg if Fun is not a function of arity 2