Result
Import Result for operations with an explicit success or error branch.
Type and constructors
Result
Result(e, a) contains an error of type e or a successful value of type a.
Err
The error branch.
Ok
The success branch. Both constructors are available to patterns.
Transforming
resultMap
Transforms the value inside Ok and preserves Err unchanged.
resultMapError
Transforms the value inside Err and preserves Ok unchanged.
resultAndThen
Calls the function for Ok and returns its result without nesting. Err skips
the function and passes through.
resultRecover
Calls the recovery function for Err. Ok skips recovery and keeps its value.
The recovery may change the error type.
All transformation operations are O(1) apart from the callback.
Defaults and inspection
resultWithDefault
Uses the first argument only for Err.
resultIsOk
resultIsErr
Conversion
resultToMaybe
Converts Ok value to Just value and discards an error as Nothing.
resultErrorToMaybe
Converts Err error to Just error and discards a success as Nothing.
resultFromMaybe
Converts Just value to Ok value. Nothing becomes Err containing the
error supplied first.
Conversions are O(1). Use Maybe when absence needs no error value.