New features
- New functions
unwrap_or_else(f, x::Result)andunwrap_error_or_else. The former is equivalent to (but more efficient than)is_error(x) ? f(unwrap_error(x)) : unwrap(x). The latter is the mirror image. - New function
ok(::Result)::Optionconstructs anOptionfrom aResult, discarding the error value by turning an error value into anone. - New function
is_ok_and(f, x::Result)is equivalent to, but more efficient than!is_error(x) && f(unwrap(x)). - New function
iter(x::Option)return an iterator which is empty ifxis none, and contains only the result value otherwise.
New features
- New function
map_or(f, x::Result, v). Returnsf(unwrap(x))if x is a result value, elsev
Breaking changes
- Renamed
unwrap_errandexpect_errtounwrap_errorandexpect_error.
New features
@unwrap_error_orandunwrap_error_ormirrors their non-error equivalents.
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 constructResulttypes 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-valuedOptionof an abstract type, e.g.Option{Integer}(some(1)). - The
@?macro now propagates more easily, and can propagate an error value of typeResultto anOption.
New features
- New function:
base(::Option{T}). Converts anOption{T}into aUnion{Some{T}, Nothing}.
Breaking changes
Option{T}has been revamped and is now an alias ofResult{T, Nothing}. As a consequence, most code that usedOptionis now broken.Option-specific functionsThing,None,is_none,expect_noneandunwrap_nonehave been removed.noneis 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 <: O2andE1 <: E2. @? xwhenxis aResult{O, E}containing anErrwith valuevnow evaluates toreturn Err(v)instead ofreturn x. This allows a value of oneResulttype 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 theResultconains anOk. - New function:
expect_err(::Result, ::AbstractString). Similar tounwrap_err, but throws an error with a custom message.
Breaking changes
None
New features
- New function
unwrap_or(x::Union{Option, Result}, v). Returnsvifxis an error value, else unwrapx. - New macro
@unwrap_or x expr. Similar to the functionunwrap_or, but does not evaluateexprifxis not an error type. Allows you to do e.g.@unwrap or x breakto break out of a loop if you encounter an error value. - New function
and_then(f, x::Union{Option, Result}). Returnsxif it's an error value, else returnsf(unwrap(x)), wrapped as the same type asx.
Initial release