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
assert_valid_keys(map, keys)
Specs
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
atomize_keys(map)
deep_atomize_keys(map)
deep_stringify_keys(map)
Specs
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}}]}}
deep_symbolize_keys(map)
Specs
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}}]}}
deep_transform_keys(map, func)
Specs
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}}]}}
deep_transform_values(map, func)
Specs
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"}}]}}
stringify_keys(map)
Specs
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"}
symbolize_keys(map)
Specs
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"}