Phoenix API Toolkit v0.8.0 PhoenixApiToolkit.Utils View Source

Generic utility functions.

Link to this section Summary

Functions

Get a mandatory value from a keyword list. Raises an ArgumentError if the key is missing from the list (or its value is nil).

Link to this section Functions

Link to this function

get_keyword!(keyword_list, key)

View Source
get_keyword!(Keyword.t(), atom()) :: any()

Get a mandatory value from a keyword list. Raises an ArgumentError if the key is missing from the list (or its value is nil).

Examples

# if the key-value pair is present, its value is returned
iex> [secret: "supersecret"] |> get_keyword!(:secret)
"supersecret"

# if the key-value pair is not present, an error is raised
iex> [] |> get_keyword!(:secret)
** (ArgumentError) key "secret" not found

# if the value is nil, an error is raised
iex> [secret: nil] |> get_keyword!(:secret)
** (ArgumentError) key "secret" not found