Extra v0.2.0 Map.Extra

Extensions to the built-in Map module.

Link to this section Summary

Functions

Raises an ArgumentError error if map does not have the provided key

Raises an ArgumentError if map does not have all of the provided keys

Returns true if the map has all of the keys

Takes the fields specified by keys from map if their values are present and non nil

Link to this section Functions

Link to this function assert_key!(map, key, opts \\ [])
assert_key!(map, atom, keyword) :: :ok | no_return

Raises an ArgumentError error if map does not have the provided key.

Options

  • :message: binary, the message to raise with when the value is missing.
  • :allow_nil_value: boolean, Default: true. Set to true if a nil value should not raise.
Link to this function assert_keys!(map, keys, opts \\ [])
assert_keys!(map, [key :: any], keyword) :: :ok | no_return

Raises an ArgumentError if map does not have all of the provided keys.

Options

  • :message: binary, the message to raise with when the value is missing.
  • :allow_nil_value: boolean, Default: true. Set to true if a nil value should not raise.
Link to this function has_keys?(map, keys)
has_keys?(map, Enum.t) :: boolean

Returns true if the map has all of the keys.

Link to this function take_non_nil(map, keys)
take_non_nil(map, list) :: map

Takes the fields specified by keys from map if their values are present and non nil.

Examples

iex> Map.Extra.take_non_nil(%{name: nil}, [:name]) %{}

iex> Map.Extra.take_non_nil(%{name: “Jerome”}, [:name]) %{name: “Jerome”}