True Myth / toolbelt / fromResult
Function: fromResult()
fromResult<
T
>(result
):Maybe
<T
>
Construct a Maybe<T>
from a Result<T, E>
.
If the Result
is a Ok
, wrap its value in Just
. If the Result
is an Err
, throw away the wrapped E
and transform to a Nothing
.
Type Parameters
T
T
extends object
The type of the value wrapped in a Ok
and therefore in the Just
of the resulting Maybe
.
Parameters
result
Result
<T
, unknown
>
The Result
to construct a Maybe
from.
Returns
Maybe
<T
>
Just
if result
was Ok
or Nothing
if it was Err
.