DarkMatter.Maps (DarkMatter v1.1.4) View Source

Utils for handling maps

Link to this section Summary

Functions

Determine if a map keys are of type atom/0.

Determine if a map keys are of type atom/0.

Provide indifferent access to maps.

Determine if a map keys are of type atom/0.

Returns a sorted list of atom keys found in results.

Determine if a map keys are of type String.t/0.

Classifies a map by key type.

Classifies a kv pair by key type.

Link to this section Types

Specs

access_key() :: atom() | String.t()

Specs

access_key_or_keys() :: access_key() | [access_key(), ...]

Specs

accessor_path() :: iget_key() | [iget_key(), ...]

Specs

iget_key() :: atom()

Specs

kv() :: {any(), any()}

Specs

kv_type() :: :atom | :string | :complex

Specs

map_keys_type() :: kv_type() | :mixed | :empty

Link to this section Functions

Link to this function

access_in(map, key_or_keys, default \\ nil)

View Source

Specs

access_in(map(), access_key_or_keys(), any()) :: any()

Safe version of Kernel.get_in/2

Link to this function

atom_keys?(map)

View Source (since 1.1.4)

Specs

atom_keys?(map()) :: boolean()

Determine if a map keys are of type atom/0.

Examples

iex> atom_keys?(%{})
true

iex> atom_keys?(%URI{})
true

iex> atom_keys?(%{atom: true})
true

iex> atom_keys?(%{"string" =>  true})
false

iex> atom_keys?(%{[] =>  "complex"})
false

iex> atom_keys?(%{:atom =>  true, "string" =>  true})
false
Link to this function

compact(map_or_struct, opts \\ %{allow_nil: false, deep: false})

View Source

Specs

compact(map() | struct(), opts :: Keyword.t() | map()) :: map()

Returns a map with nil values omitted

Link to this function

complex_keys?(map)

View Source (since 1.1.4)

Specs

complex_keys?(map()) :: boolean()

Determine if a map keys are of type atom/0.

Examples

iex> complex_keys?(%{})
true

iex> complex_keys?(%URI{})
false

iex> complex_keys?(%{atom: true})
false

iex> complex_keys?(%{"string" =>  true})
false

iex> complex_keys?(%{[] =>  "complex"})
true

iex> complex_keys?(%{:atom =>  true, "string" =>  true})
false
Link to this function

iget(map, key)

View Source (since 1.1.2)

Specs

iget(map(), accessor_path()) :: any()

Provide indifferent access to maps.

Link to this function

iget(map, key_or_keys, default)

View Source

Specs

iget(map(), accessor_path(), any()) :: any()
Link to this function

mixed_keys?(map)

View Source (since 1.1.4)

Specs

mixed_keys?(map()) :: boolean()

Determine if a map keys are of type atom/0.

Examples

iex> mixed_keys?(%{})
true

iex> mixed_keys?(%URI{})
false

iex> mixed_keys?(%{atom: true})
false

iex> mixed_keys?(%{"string" =>  true})
false

iex> mixed_keys?(%{[] =>  "complex"})
false

iex> mixed_keys?(%{:atom =>  true, "string" =>  true})
true

Specs

sorted_keys(map()) :: [atom() | String.t(), ...]

Returns a sorted list of atom keys found in results.

Link to this function

string_keys?(map)

View Source (since 1.1.4)

Specs

string_keys?(map()) :: boolean()

Determine if a map keys are of type String.t/0.

Examples

iex> string_keys?(%{})
true

iex> string_keys?(%URI{})
false

iex> string_keys?(%{atom: true})
false

iex> string_keys?(%{"string" =>  true})
true

iex> string_keys?(%{[] =>  "complex"})
false

iex> string_keys?(%{:atom =>  true, "string" =>  true})
false
Link to this function

typeof_keys(struct)

View Source (since 1.1.4)

Specs

typeof_keys(map() | struct()) :: map_keys_type()

Classifies a map by key type.

Examples

iex> typeof_keys(%{})
:empty

iex> typeof_keys(%URI{})
:atom

iex> typeof_keys(%{atom: true})
:atom

iex> typeof_keys(%{"string" =>  true})
:string

iex> typeof_keys(%{[] =>  "complex"})
:complex

iex> typeof_keys(%{:atom =>  true, "string" =>  true})
:mixed
Link to this function

typeof_kv(arg)

View Source (since 1.1.4)

Specs

typeof_kv(kv()) :: kv_type()

Classifies a kv pair by key type.

Examples

iex> typeof_kv({:atom, true})
:atom

iex> typeof_kv({"string", true})
:string

iex> typeof_kv({[], true})
:complex