cldr_utils v2.4.0 Cldr.Map View Source
Functions for transforming maps, keys and values.
Link to this section Summary
Functions
Transforms a map's String.t keys to atom() keys.
Transforms a map's String.t values to atom() values.
Recursively traverse a map and invoke a function for each key/ value pair that transforms the map.
Recursively traverse a map and invoke a function for each key and a function for each value that transform the map.
Deep merge two maps
Delete all members of a map that have a key in the list of keys
Transforms a map's values to Float.t values.
Transforms a map's keys to Integer.t keys.
Transforms a map's values to Integer.t values.
Returns the result of deep merging a list of maps
Removes any leading underscores from map
keys.
Rename map keys from from to to
Transforms a map's atom() keys to String.t keys.
Convert a camelCase string or atome to a snake_case
Convert map keys from camelCase to snake_case
Link to this section Functions
Transforms a map's String.t keys to atom() keys.
mapis anymap/0optionsis a keyword list of options. The available option is::only_existingwhich is set totruewill only convert the binary key to an atom if the atom already exists. The default isfalse.
Examples
Transforms a map's String.t values to atom() values.
mapis anymap/0optionsis a keyword list of options. The available option is::only_existingwhich is set totruewill only convert the binary value to an atom if the atom already exists. The default isfalse.
Examples
Recursively traverse a map and invoke a function for each key/ value pair that transforms the map.
Arguments
mapis anymap/0functionis a function or function reference that is called for each key/value pair of the provided map
Returns
- The
maptransformed by the recursive application offunction
Example
iex> map = %{a: "a", b: %{c: "c"}} iex> Cldr.Map.deep_map map, fn {k, v} -> ...> {k, String.upcase(v)} ...> end %{a: "A", b: %{c: "C"}}
Recursively traverse a map and invoke a function for each key and a function for each value that transform the map.
mapis anymap/0key_functionis a function or function reference that is called for each key of the provided map and any keys of any submapsvalue_functionis a function or function reference that is called for each value of the provided map and any values of any submaps
Returns:
- The
maptransformed by the recursive application ofkey_functionandvalue_function
Examples
Deep merge two maps
Examples
iex> Cldr.Map.deep_merge %{a: "a", b: "b"}, %{c: "c", d: "d"}
%{a: "a", b: "b", c: "c", d: "d"}
iex> Cldr.Map.deep_merge %{a: "a", b: "b"}, %{c: "c", d: "d", a: "aa"}
%{a: "aa", b: "b", c: "c", d: "d"}
Delete all members of a map that have a key in the list of keys
Examples
iex> Cldr.Map.delete_in %{a: "a", b: "b"}, [:a]
%{b: "b"}
Transforms a map's values to Float.t values.
mapis anymap/0
The map value is converted to a float from
either an atom or String.t only when the
value is comprised of a valid float forma.
Keys which cannot be converted to a float
are returned unchanged.
Examples
Transforms a map's keys to Integer.t keys.
mapis anymap/0
The map key is converted to an integer from
either an atom or String.t only when the
key is comprised of integer digits.
Keys which cannot be converted to an integer
are returned unchanged.
Examples
Transforms a map's values to Integer.t values.
mapis anymap/0
The map value is converted to an integer from
either an atom or String.t only when the
value is comprised of integer digits.
Keys which cannot be converted to an integer are returned unchanged.
Examples
Returns the result of deep merging a list of maps
Examples
iex> Cldr.Map.merge_map_list [%{a: "a", b: "b"}, %{c: "c", d: "d"}]
%{a: "a", b: "b", c: "c", d: "d"}
Removes any leading underscores from map
keys.
mapis anymap/0
Examples
Rename map keys from from to to
mapis anymap/0fromis any value map keytois any valud map key
Examples
Transforms a map's atom() keys to String.t keys.
mapis anymap/0
Examples
Convert a camelCase string or atome to a snake_case
stringis aString.toratom()to be transformed
This is the code of Macro.underscore with modifications. The change is to cater for strings in the format:
This_That
which in Macro.underscore gets formatted as
this__that (note the double underscore)
when we actually want
that_that
Examples
Convert map keys from camelCase to snake_case
mapis anymap/0