rightToMaybe
rightToMaybe<
T>(x):TextendsRight<infer R> ?TextendsLeft<unknown> ?Maybe<R> :R:Nothing
Converts a Right value from an Either type to a Just type, or returns Nothing if the value is Left.
Example
rightToMaybe({right: "foo"})// => "foo"
rightToMaybe({left: "bar"})// => NothingType Parameters
• T extends Either<unknown, unknown>
The type of the Either. It determines the type encapsulated if Right.
Parameters
x
T
The Either object to examine. This function checks if it is a Right and extracts its value.
Returns
T extends Right<infer R> ? T extends Left<unknown> ? Maybe<R> : R : Nothing
A Maybe type, wrapping the Right value if present; otherwise, Nothing.