Skip to content

leftToMaybe

leftToMaybe<T>(x): T extends Left<infer L> ? T extends Right<unknown> ? Maybe<L> : L : Nothing

Converts a Left type from an Either into a Maybe. If the input is a Left, the value is returned as a Just. Otherwise, if the input is a Right, Nothing is returned.

Example

leftToMaybe({left: "error"})
// => "error"
leftToMaybe({right: 42})
// => Nothing

Type Parameters

T extends Either<unknown, unknown>

The type of the Either value.

Parameters

x

T

The Either value to be converted.

Returns

T extends Left<infer L> ? T extends Right<unknown> ? Maybe<L> : L : Nothing

A Maybe wrapping the left value, or Nothing.