maybeToLeft
maybeToLeft<
T
,R
>(x
,right
): [Nothing
] extends [T
] ?IsEqual
<T
,Nothing
> extendstrue
?Right
<R
> :Either
<Just
<T
>,R
> :Left
<T
>
Transforms a Maybe value into an Either type, returning a Left containing the Just value. If the Maybe is Nothing, it returns a Right with a specified default value.
Example
maybeToLeft("foo", "fallback")// => {left: "foo"}
maybeToLeft(Nothing, "fallback")// => {right: "fallback"}
Type Parameters
• T
The type held by Just in the Maybe.
• R
The type of the Right value in the returned Either.
Parameters
x
T
The Maybe value to transform. If it is a Just, it is returned as the Left part of an Either.
right
R
The default value to use for the Right part if x
is Nothing.
Returns
[Nothing
] extends [T
] ? IsEqual
<T
, Nothing
> extends true
? Right
<R
> : Either
<Just
<T
>, R
> : Left
<T
>
Either a Left containing the Just value or a Right with the default value.