Exordia v0.8.2 Exordia View Source
Exordia defines some convenience macros/functions.
Add use Exordia to modules in which you would like to use them.
Link to this section Summary
Functions
Similar to the ~> operator but passes non-errors through and calls the
function on error values unless the :handled key of the Exordia.Error
struct is true
Converts an :error, {:error, r}, or {:error, r, d} tuple into an
Exordia.Error.t() struct. Any othre value is passed through unmodified
Like exordize/1 but pipes the value into the provided function
Converts value to {:ok, value}
Converts value to {:ok, value} and pipes this as an argument into the
provided function. Useful when you want to pipe an :ok tuple using ~>
(which automatically unwraps these tuples)
Rescues exceptions, converting them into Exordia.Error.t() structs
Rescues exceptions, converting them into Exordia.Error.t() structs. Passes
the first argument into the second argument’s function call making it useful
for piping
Passes the argument to the provided function, ignoring the return value of the function and returning the first argument, making it useful for piping
Passes the argument to the provided function. Returns the first argument unless the function returns an error in which case the error is returned, making it useful for piping
Converts an Exordia.Error.t() struct into an :error, {:error, r}, or
{:error, r, d} tuple. Any other value is passed through unmodified
Like un_exordize/1 but pipes the value into the provided function
Pipe-like operator which converts :error or error tuples to Exordia.Error
structs, skips to the end of the chain on errors, and passes only value
when it encounters {:ok, value}
Link to this section Functions
Similar to the ~> operator but passes non-errors through and calls the
function on error values unless the :handled key of the Exordia.Error
struct is true.
Examples
iex> 1 <~ Tuple.to_list()
1
iex> {:ok, 1} <~ Tuple.to_list(_)
1
iex> :error <~ Kernel.inspect()
"%Exordia.Error{handled: false, meta: nil, reason: nil}"
exordize(x | {:ok, x}) :: x | Exordia.Error.t() when x: any()
Converts an :error, {:error, r}, or {:error, r, d} tuple into an
Exordia.Error.t() struct. Any othre value is passed through unmodified.
Like exordize/1 but pipes the value into the provided function.
Converts value to {:ok, value}.
Converts value to {:ok, value} and pipes this as an argument into the
provided function. Useful when you want to pipe an :ok tuple using ~>
(which automatically unwraps these tuples).
Rescues exceptions, converting them into Exordia.Error.t() structs.
Examples
iex> safe(div(10, 5))
2
iex> safe(div(10, 0))
%Exordia.Error{
handled: false,
meta: nil,
reason: %ArithmeticError{message: "bad argument in arithmetic expression"}
}
Rescues exceptions, converting them into Exordia.Error.t() structs. Passes
the first argument into the second argument’s function call making it useful
for piping.
Examples
iex> 10 |> safe(div(5))
2
iex> 10 |> safe(div(0))
%Exordia.Error{
handled: false,
meta: nil,
reason: %ArithmeticError{message: "bad argument in arithmetic expression"}
}
Passes the argument to the provided function, ignoring the return value of the function and returning the first argument, making it useful for piping.
Passes the argument to the provided function. Returns the first argument unless the function returns an error in which case the error is returned, making it useful for piping.
Converts an Exordia.Error.t() struct into an :error, {:error, r}, or
{:error, r, d} tuple. Any other value is passed through unmodified.
Like un_exordize/1 but pipes the value into the provided function.
Pipe-like operator which converts :error or error tuples to Exordia.Error
structs, skips to the end of the chain on errors, and passes only value
when it encounters {:ok, value}.
An underscore can be used to pipe the argument to an arbitrary position.
Examples
iex> 1 ~> Kernel.to_string()
"1"
iex> {:ok, 1} ~> Kernel.to_string(_)
"1"
iex> {:error, :something_bad} ~> Kernel.to_string()
%Exordia.Error{handled: false, meta: nil, reason: :something_bad}