This method is unsafe, and should only be used in a test environments
Takes a Result<T, E>
and returns a T
when the result is an Ok
, otherwise it throws a custom object.
Optional
_: ErrorConfigThis method is unsafe, and should only be used in a test environments
takes a Result<T, E>
and returns a E
when the result is an Err
,
otherwise it throws a custom object.
Optional
config: ErrorConfigThis "tee"s the current value to an passed-in computation such as side effect functions but still returns the same current value as the result.
This is useful when you want to pass the current result to your side-track work such as logging but want to continue main-track work after that. This method does not care about the result of the passed in computation.
The function to apply to the current value
Similar to map
Except you must return a new Result
.
This is useful for when you need to do a subsequent computation using the
inner T
value, but that computation might fail.
Additionally, andThen
is really useful as a tool to flatten a
Result<Result<A, E2>, E1>
into a Result<A, E2>
(see example below).
Given 2 functions (one for the Ok
variant and one for the Err
variant)
execute the function that matches the Result
variant.
Match callbacks do not necessitate to return a Result
, however you can
return a Result
if you want to.
match
is like chaining map
and mapErr
, with the distinction that
with match
both functions must have the same return type.
This "tee"s the current Err
value to an passed-in computation such as side
effect functions but still returns the same Err
value as the result.
This is useful when you want to pass the current Err
value to your side-track
work such as logging but want to continue error-track work after that.
This method does not care about the result of the passed in computation.
An
Ok
instance is the successful variant of the Result type, representing a successful outcome from an operation which may fail.Implemented using
neverthrow