ResultTypes API
Constructors
ResultTypes.Result
— Type.Result(val::T, exception_type::Type{E}=Exception) -> Result{T, E}
Create a Result
that could hold a value of type T
or an exception of type E
, and store val
in it. If the exception type is not provided, the supertype Exception
is used as E
.
ResultTypes.ErrorResult
— Function.ErrorResult(::Type{T}, exception::E) -> Result{T, E}
ErrorResult(::Type{T}, exception::AbstractString="") -> Result{T, ErrorException}
Create a Result
that could hold a value of type T
or an exception of type E
, and store exception
in it. If the exception
is provided as text, it is wrapped in the generic ErrorException
. If no exception is provided, an ErrorException
with an empty string is used. If the type argument is not provided, Any
is used.
ErrorResult
is a convenience function for creating a Result
and is not its own type.
Functions
ResultTypes.unwrap
— Function.unwrap(result::Result{T, E}) -> T
unwrap(val::T) -> T
unwrap(::Type{T}, result_or_val) -> T
Assumes result
holds a value of type T
and returns it. If result
holds an exception instead, that exception is thrown.
If unwrap
's argument is not a Result
, it is returned.
The two-argument form of unwrap
calls unwrap
on its second argument, then converts it to type T
.
ResultTypes.unwrap_error
— Function.unwrap_error(result::Result{T, E}) -> E
unwrap_error(exception::E) -> E
Assumes result
holds an exception of type E
and returns it. If result
holds a value instead, throw an exception.
If unwrap_error
's argument is an Exception
, that exception is returned.
ResultTypes.iserror
— Function.ResultTypes.iserror(x) -> Bool
If x
is an Exception
, return true
. If x
is an ErrorResult
(a Result
containing an Exception
), return true
. Return false
in all other cases.