Releases: jakobnissen/ErrorTypes.jl
Releases · jakobnissen/ErrorTypes.jl
v0.5.1
v0.5
Release 0.5.0
Breaking changes
- Renamed
unwrap_err
andexpect_err
tounwrap_error
andexpect_error
.
New features
@unwrap_error_or
andunwrap_error_or
mirrors their non-error equivalents.
v0.4
Release 0.4
Breaking changes
ErrorTypes is no longer based on SumTypes. SumTypes tries to solve a more general problem, and as such requires more compiler tricks. That both obfuscated ErrorTypes' behaviour and made it a more heavy dependency than it needed to be.
- The constructors
Err{T, E}(x)
andOk{T, E}(x)
have been removed. You should constructResult
types like this:Result{T, E}(Err(x))
.
Several internal types and representations have also changed.
New features
- You can now use the syntax
Option{T}(some(x))
to create a result-valuedOption
of an abstract type, e.g.Option{Integer}(some(1))
. - The
@?
macro now propagates more easily, and can propagate an error value of typeResult
to anOption
.
v0.3.1
Release 0.3.1
New features
- New function:
base(::Option{T})
. Converts anOption{T}
into aUnion{Some{T}, Nothing}
.
v0.3
Release 0.3
Breaking changes
Option{T}
has been revamped and is now an alias ofResult{T, Nothing}
. As a consequence, most code that usedOption
is now broken.Option
-specific functionsThing
,None
,is_none
,expect_none
andunwrap_none
have been removed.none
is now a const forErr(nothing)
, but works similarly as before.none(::Type{T})
now creates anErr{T, Nothing}(nothing)
, e.g.none(T)
behaves likeNone{T}()
before.some(x)
creates anOk{typeof(x), Nothing}(x)
, e.g. it's likeThing(x)
before.- It is now ONLY possible to convert a
Result{O1, E1}
to aResult{O2, E2}
ifO1 <: O2
andE1 <: E2
. @? x
whenx
is aResult{O, E}
containing anErr
with valuev
now evaluates toreturn Err(v)
instead ofreturn x
. This allows a value of oneResult
type to be propagated to another.- The function
and_then
, now has the signatureand_then(f, ::Type{T}, x::Union{Option, Result})
, in order to prevent excessive type instability.
New features
- An
Option{T}
can now be constructed from aResult{T}
, yielding the error value if the result contains an error value. - A
Result{O, E}
can now be constructed usingResult(::Option{O}, e::E)
. If the option contains an error value, this will result inErr{O, E}(e)
. - New function
flatten
. Turns anOption{Option{T}}
into anOption{T}
. - New function:
unwrap_err(::Result)
. Unwraps the wrapped error type of aResult
, and throws an error if theResult
conains anOk
. - New function:
expect_err(::Result, ::AbstractString)
. Similar tounwrap_err
, but throws an error with a custom message.
v0.2
Release 0.2
Breaking changes
None
New features
- New function
unwrap_or(x::Union{Option, Result}, v)
. Returnsv
ifx
is an error value, else unwrapx
. - New macro
@unwrap_or x expr
. Similar to the functionunwrap_or
, but does not evaluateexpr
ifx
is not an error type. Allows you to do e.g.@unwrap or x break
to break out of a loop if you encounter an error value. - New function
and_then(f, x::Union{Option, Result})
. Returnsx
if it's an error value, else returnsf(unwrap(x))
, wrapped as the same type asx
.
v0.1
Initial release