xema v0.9.2 Xema.Utils View Source
Some utilities for Xema.
Link to this section Summary
Functions
Returns whether the given key exists in the given value.
Returns the size of a list or tuple.
Converts the given string to an existing atom. Returns nil if the
atom does not exist.
Returns nil if uri_1 and uri_2 are nil.
Parses a URI when the other URI is nil.
Merges URIs if both are not nil.
Link to this section Functions
Link to this function
has_key?(value, key) View Source
Returns whether the given key exists in the given value.
Returns true if
valueis a map and containskeyas a key.valueis a keyword and containskeyas a key.valueis a list of tuples withkeyas the first element.
Example
iex> alias Xema.Utils
iex> Utils.has_key?(%{foo: 5}, :foo)
true
iex> Utils.has_key?([foo: 5], :foo)
true
iex> Utils.has_key?([{"foo", 5}], "foo")
true
Link to this function
size(list) View Source
Returns the size of a list or tuple.
Link to this function
to_existing_atom(atom) View Source
Converts the given string to an existing atom. Returns nil if the
atom does not exist.
Examples
iex> import Xema.Utils
iex> to_existing_atom(:my_atom)
:my_atom
iex> to_existing_atom("my_atom")
:my_atom
iex> to_existing_atom("not_existing_atom")
nil
Link to this function
update_uri(uri_1, uri_2) View Source
Returns nil if uri_1 and uri_2 are nil.
Parses a URI when the other URI is nil.
Merges URIs if both are not nil.