Umbra v0.0.3 Umbra.Helper View Source
This module is used under the hood by all Umbra modules.
It defines some helpers.
Link to this section Summary
Functions
This function is used to extract argument.
This function is used to extract function name and arguments.
This macro help know if the given atom is a valid name for functions or variables. It should be used in when guards.
Link to this section Functions
Specs
This function is used to extract argument.
It returns an atom corresponding to the argument name.
When the function did fails, it raises ArgumentError
.
Example:
iex> Umbra.Helper.extract_argument(:my_arg)
:my_arg
iex> Umbra.Helper.extract_argument(quote do: :my_arg)
:my_arg
iex> Umbra.Helper.extract_argument(quote do: a_var)
:a_var
iex> Umbra.Helper.extract_argument(quote do: :def)
** (ArgumentError) invalid argument
iex> Umbra.Helper.extract_argument(quote do: %{something: true})
** (ArgumentError) invalid argument
Specs
This function is used to extract function name and arguments.
It returns a tuple with the function name and the arguments.
When the function did fails, it raises ArgumentError
.
Example:
iex> Umbra.Helper.extract_definition(:get_state)
{:get_state, []}
iex> Umbra.Helper.extract_definition(quote do: :get_state)
{:get_state, []}
iex> Umbra.Helper.extract_definition(quote do: {:get_state})
{:get_state, []}
iex> Umbra.Helper.extract_definition(quote do: get_state())
{:get_state, []}
iex> Umbra.Helper.extract_definition(quote do: {:set_state, new_state})
{:set_state, [:new_state]}
iex> Umbra.Helper.extract_definition(quote do: set_state(new_state))
{:set_state, [:new_state]}
iex> Umbra.Helper.extract_definition(quote do: {:do_something, a, b})
{:do_something, [:a, :b]}
iex> Umbra.Helper.extract_definition(quote do: do_something(a, b))
{:do_something, [:a, :b]}
iex> Umbra.Helper.extract_definition(quote do: def(a))
** (ArgumentError) invalid definition
iex> Umbra.Helper.extract_definition(quote do: my_func(def))
** (ArgumentError) invalid argument
iex> Umbra.Helper.extract_definition(quote do: my_func(%{something: true}))
** (ArgumentError) invalid argument
This macro help know if the given atom is a valid name for functions or variables. It should be used in when guards.
Example:
iex> Umbra.Helper.var_name?(:toto) true
iex> Umbra.Helper.var_name?(:tata) true
iex> Umbra.Helper.var_name?(:%{}) false