True Myth / toolbelt / toOkOrElseErr
Function: toOkOrElseErr()
Call Signature
toOkOrElseErr<
T
,E
>(elseFn
,maybe
):Result
<T
,E
>
Transform the Maybe
into a Result
, using the wrapped value as the Ok
value if the Maybe
is Just
; otherwise using elseFn
to generate the Err
.
Type Parameters
T
T
The wrapped value.
E
E
The error type to in the Result
.
Parameters
elseFn
() => E
The function which generates an error of type E
.
maybe
Maybe
<T
>
The Maybe
instance to convert.
Returns
Result
<T
, E
>
A Result
containing the value wrapped in maybe
in an Ok
, or the value generated by elseFn
in an Err
.
Call Signature
toOkOrElseErr<
T
,E
>(elseFn
): (maybe
) =>Result
<T
,E
>
Transform the Maybe
into a Result
, using the wrapped value as the Ok
value if the Maybe
is Just
; otherwise using elseFn
to generate the Err
.
Type Parameters
T
T
The wrapped value.
E
E
The error type to in the Result
.
Parameters
elseFn
() => E
The function which generates an error of type E
.
Returns
A Result
containing the value wrapped in maybe
in an Ok
, or the value generated by elseFn
in an Err
.
(
maybe
):Result
<T
,E
>
Parameters
maybe
Maybe
<T
>
Returns
Result
<T
, E
>