RMap.ActiveSupport (REnum v0.8.0)

Summarized all of Hash functions in Rails.ActiveSupport. If a function with the same name already exists in Elixir, that is not implemented. Defines all of here functions when use RMap.ActiveSupport.

Link to this section Summary

Functions

Validates all keys in a map match given keys, raising ArgumentError on a mismatch.

Returns a list with all keys converted to strings. This includes the keys from the root map and from all nested maps and arrays.

Returns a list with all keys converted to atom. This includes the keys from the root map and from all nested maps and arrays.

Returns a map with all keys converted by the function. This includes the keys from the root map and from all nested maps and arrays.

Returns a map with all values converted by the function. This includes the keys from the root map and from all nested maps and arrays.

Returns a map with all keys converted to strings.

Returns a map with all keys converted to atom.

Link to this section Functions

Link to this function

assert_valid_keys(map, keys)

Specs

assert_valid_keys(map(), list()) :: :ok

Validates all keys in a map match given keys, raising ArgumentError on a mismatch.

Examples

iex> RMap.assert_valid_keys(%{name: "Rob", years: "28"}, [:name, :age])
** (ArgumentError) Unknown key: years. Valid keys are: name, age

iex> RMap.assert_valid_keys(%{name: "Rob", age: "28"}, ["age"])
** (ArgumentError) Unknown key: age. Valid keys are: age

iex> RMap.assert_valid_keys(%{name: "Rob", age: "28"}, [:name, :age])
:ok
Link to this function

atomize_keys(map)

See RMap.ActiveSupport.symbolize_keys/1.

Link to this function

deep_atomize_keys(map)

See RMap.ActiveSupport.deep_symbolize_keys/1.

Link to this function

deep_stringify_keys(map)

Specs

deep_stringify_keys(map()) :: map()

Returns a list with all keys converted to strings. This includes the keys from the root map and from all nested maps and arrays.

Examples

iex> RMap.deep_stringify_keys(%{name: "Rob", years: "28", nested: %{ a: 1 }})
%{"name" => "Rob", "nested" => %{"a" => 1}, "years" => "28"}

iex> RMap.deep_stringify_keys(%{a: %{b: %{c: 1}, d: [%{a: 1, b: %{c: 2}}]}})
%{"a" => %{"b" => %{"c" => 1}, "d" => [%{"a" => 1, "b" => %{"c" => 2}}]}}
Link to this function

deep_symbolize_keys(map)

Specs

deep_symbolize_keys(map()) :: map()

Returns a list with all keys converted to atom. This includes the keys from the root map and from all nested maps and arrays.

Examples

iex> RMap.deep_symbolize_keys(%{"name" => "Rob", "years" => "28", "nested" => %{ "a" => 1 }})
%{name: "Rob", nested: %{a: 1}, years: "28"}

iex> RMap.deep_symbolize_keys(%{"a" => %{"b" => %{"c" => 1}, "d" => [%{"a" => 1, "b" => %{"c" => 2}}]}})
%{a: %{b: %{c: 1}, d: [%{a: 1, b: %{c: 2}}]}}
Link to this function

deep_transform_keys(map, func)

Specs

deep_transform_keys(map(), function()) :: map()

Returns a map with all keys converted by the function. This includes the keys from the root map and from all nested maps and arrays.

Examples

iex> RMap.deep_transform_keys(%{a: %{b: %{c: 1}}}, &to_string(&1))
%{"a" => %{"b" => %{"c" => 1}}}

iex> RMap.deep_transform_keys(%{a: %{b: %{c: 1}, d: [%{a: 1, b: %{c: 2}}]}}, &inspect(&1))
%{":a" => %{":b" => %{":c" => 1}, ":d" => [%{":a" => 1, ":b" => %{":c" => 2}}]}}
Link to this function

deep_transform_values(map, func)

Specs

deep_transform_values(map(), function()) :: map()

Returns a map with all values converted by the function. This includes the keys from the root map and from all nested maps and arrays.

Examples

iex> RMap.deep_transform_values(%{a: %{b: %{c: 1}}, d: 2}, &inspect(&1))
%{a: %{b: %{c: "1"}}, d: "2"}

iex> RMap.deep_transform_values(%{a: %{b: %{c: 1}, d: [%{a: 1, b: %{c: 2}}]}}, &inspect(&1))
%{a: %{b: %{c: "1"}, d: [%{a: "1", b: %{c: "2"}}]}}
Link to this function

stringify_keys(map)

Specs

stringify_keys(map()) :: map()

Returns a map with all keys converted to strings.

Examples

iex> RMap.stringify_keys(%{name: "Rob", years: "28", nested: %{ a: 1 }})
%{"name" => "Rob", "nested" => %{a: 1}, "years" => "28"}
Link to this function

symbolize_keys(map)

Specs

symbolize_keys(map()) :: map()

Returns a map with all keys converted to atom.

Examples

iex> RMap.symbolize_keys(%{"name" => "Rob", "years" => "28", "nested" => %{ "a" => 1 }})
%{name: "Rob", nested: %{"a" => 1}, years: "28"}