Extra v0.2.0 Keyword.Extra
Extensions to the built-in Keyword module.
Link to this section Summary
Functions
Raises an ArgumentError error if list does not have the provided key
Fetches the values for the specified keys
Gets the values for the specified keys
Raises an ArgumentError error if list contains the provided key
Takes all entries corresponding to the given keys and returns them in a new
keyword list in the order that keys arrived
Link to this section Types
Link to this section Functions
Raises an ArgumentError error if list 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 anilvalue should not raise.
Fetches the values for the specified keys.
If any of the keys do not exist, a KeyError is raised.
Examples
iex> Keyword.Extra.fetch_keys!([color: “blue”], [:color]) [“blue”]
Gets the values for the specified keys.
Pass default values for keys using the following format: {key, default}. If any of the keys do
not exist, return nil or use the default value if supplied.
Examples
iex> Keyword.Extra.get_keys([ssn: “1234”, age: 41], [:age, :ssn]) [41, “1234”]
iex> Keyword.Extra.get_keys([first_name: “Bob”], [first_name: :missing, last_name: :missing]) [“Bob”, :missing]
Raises an ArgumentError error if list contains the provided key.
Takes an optional argument specifying the error message.
Takes all entries corresponding to the given keys and returns them in a new
keyword list in the order that keys arrived.
Examples
iex> Keyword.Extra.take_ordered([c: 3, b: 2, a: 1], [:a, :b]) [a: 1, b: 2]
iex> Keyword.Extra.take_ordered([x: 1, y: 2], [:x, :y, :z]) [x: 1, y: 2]
iex> location = %{state: “NY”, city: “Manhattan”, zip_code: “10009”} …> Keyword.Extra.take_ordered(location, [:city, :state, :zip_code]) [city: “Manhattan”, state: “NY”, zip_code: “10009”]