Skip to content

maybeToRight

maybeToRight<L, T>(x, left): [Nothing] extends [T] ? IsEqual<T, Nothing> extends true ? Left<L> : Either<L, Just<T>> : Right<T>

Converts a Maybe value to an Either type. If the input is a Just, it returns the value as a Right. If the input is Nothing, it returns a specified default value as a Left.

Example

maybeToRight("foo", "foobar")
// => {right: "foo"}
maybeToRight(Nothing, "foobar")
// => {left: "foobar"}

Type Parameters

L

The type of the default value, and of the Left result.

T

The type encapsulated in Just, if x is Just.

Parameters

x

T

The Maybe value to evaluate.

left

L

The default value to use if x is Nothing.

Returns

[Nothing] extends [T] ? IsEqual<T, Nothing> extends true ? Left<L> : Either<L, Just<T>> : Right<T>

An Either type, encapsulating the value in a Right if x is Just, or the default in a Left if x is Nothing.