Module mapz

Data Types

combiner()

combiner() = fun((Path::path(), Old::term(), New::term()) -> term())

iterator()

abstract datatype: 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.

path()

path() = [term()]

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

Function Index

deep_find/2Returns a tuple {ok,Value}, where Value is the value associated with Path, or error if no value is associated with Path in Map.
deep_get/2Returns value Value associated with Path if Map contains Path.
deep_get/3Returns value Value associated with Path if Map contains Path.
deep_intersect/2Intersects two maps into a single map Map3.
deep_intersect_with/3Intersects two maps into a single map Map3.
deep_iterator/1Returns a map iterator Iterator that can be used by deep_next/1 to recursively traverse the path-value associations in a deep map structure.
deep_merge/1Merges a list of maps recursively into a single map.
deep_merge/2Equivalent to deep_merge([Map1, Map2]).
deep_merge/3(Deprecated.) Merges a list of maps Maps recursively into a single map Target.
deep_merge_with/2Merges a list of maps Maps recursively into a single map.
deep_merge_with/3Merges a list of maps Maps recursively into a single map.
deep_next/1Returns the next path-value association in Iterator and a new iterator for the remaining associations in the iterator.
deep_put/3Associates Path with value Value and inserts the association into map Map2.
deep_remove/2Removes the last existing key of Path, and its associated value from Map1 and returns a new map Map2 without that key.
deep_search/2Returns 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.
deep_update/3If Path exists in Map1, the old associated value is replaced by value Value.
deep_update_with/3Update a value in a Map1 associated with Path by calling Fun on the old value to get a new value.
deep_update_with/4Update a value in a Map1 associated with Path by calling Fun on the old value to get a new value.
inverse/1Inverts a map by inserting each value as the key with its corresponding key as the value.
inverse/2Inverts a map by inserting each value as the key with its corresponding key as the value.

Function Details

deep_find/2

deep_find(Path::path(), Map::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:

deep_get/2

deep_get(Path::path(), Map::map()) -> term()

Returns value Value associated with Path if Map contains Path.

The call can raise the following exceptions:

deep_get/3

deep_get(Path::path(), Map::map(), Default::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:

deep_intersect/2

deep_intersect(Map1::map(), Map2::map()) -> Map3::map()

Equivalent to deep_intersect_with(fun (_, _, V) -> V end, Map1, Map2).

Intersects two maps into a single map Map3. If a path exists in both maps, the value in Map1 is superseded by the value in Map2.

The call can raise the following exceptions:

deep_intersect_with/3

deep_intersect_with(Fun::combiner(), Map1::map(), Map2::map()) -> Map3::map()

Intersects two maps into a single map Map3.

If a path exists in both maps, the value in Map1 is combined with the value in Map2 by the Combiner fun. When Combiner is applied the path that exists in both maps is the first parameter, the value from Map1 is the second parameter, and the value from Map2 is the third parameter.

The call can raise the following exceptions:

deep_iterator/1

deep_iterator(Map::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.

deep_merge/1

deep_merge(Maps::[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:

deep_merge/2

deep_merge(Map1::map(), Map2::map()) -> map()

Equivalent to deep_merge([Map1, Map2]).

deep_merge/3

deep_merge(Fun::fun((Old::term(), New::term()) -> term()), Target::map(), Maps::map() | [map()]) -> map()

This function is deprecated: Use deep_merge_with/3 instead

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: map.

deep_merge_with/2

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: map.

deep_merge_with/3

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: map.

deep_next/1

deep_next(Iter::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.

deep_put/3

deep_put(Path::path(), Value::term(), Map1::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:

deep_remove/2

deep_remove(Path::path(), Map::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:

deep_search/2

deep_search(Path, Map) -> any()

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:

deep_update/3

deep_update(Path::path(), Value::term(), Map1::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:

deep_update_with/3

deep_update_with(Path::path(), Fun::fun((term()) -> term()), Map1::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:

deep_update_with/4

deep_update_with(Path::path(), Fun::fun((term()) -> term()), Init::any(), Map1::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:

inverse/1

inverse(Map::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:

inverse/2

inverse(Map::map(), Fun::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:


Generated by EDoc