cldr_utils v2.0.2 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.
map
is anymap/0
options
is a keyword list of options. The available option is::only_existing
which is set totrue
will 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.
map
is anymap/0
options
is a keyword list of options. The available option is::only_existing
which is set totrue
will 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
map
is anymap/0
function
is a function or function reference that is called for each key/value pair of the provided map
Returns
- The
map
transformed 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.
map
is anymap/0
key_function
is a function or function reference that is called for each key of the provided map and any keys of any submapsvalue_function
is a function or function reference that is called for each value of the provided map and any values of any submaps
Returns:
- The
map
transformed by the recursive application ofkey_function
andvalue_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.
map
is 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.
map
is 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.
map
is 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.
map
is anymap/0
Examples
Rename map keys from from
to to
map
is anymap/0
from
is any value map keyto
is any valud map key
Examples
Transforms a map
’s atom()
keys to String.t
keys.
map
is anymap/0
Examples
Convert a camelCase string or atome to a snake_case
string
is aString.t
oratom()
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
map
is anymap/0