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).
Similar to andTee
except error result of the computation will be passed
to the downstream in case of an error.
This version is useful when you want to make side-effects but in case of an error, you want to pass the error to the downstream.
Similar to map
Except you must return a new Result
.
This is useful for when you need to do a subsequent async computation using
the inner T
value, but that computation might fail. Must return a ResultAsync
The function that returns a ResultAsync
to apply to the current
value
Maps a Result<T, E>
to ResultAsync<U, E>
by applying an async function to a contained Ok
value, leaving an Err
value untouched.
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.
This method is unsafe, and should only be used in a test environments
Takes a
Result<T, E>
and returns aT
when the result is anOk
, otherwise it throws a custom object.