Right

data class Right<out B>(val value: B) : Either<Nothing, B>

The right side of the disjoint union, as opposed to the Left side.

Constructors

Link copied to clipboard
constructor(value: B)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
val value: B

Functions

Link copied to clipboard
inline fun <E, T : Throwable, A> Either<Throwable, A>.catch(catch: Raise<E>.(T) -> A): Either<E, A>

Variant of Either.catchOrThrow constructor that allows for working with Either<Throwable, A> by transforming or recovering from Throwable as T in the Either.Left side. This API is the same as recover. This is useful when working with results of Either.catch since this API offers a reified variant.

Link copied to clipboard
inline fun <A, B> Either<A, B>.combine(other: Either<A, B>, combineLeft: (A, A) -> A, combineRight: (B, B) -> B): Either<A, B>

Combine two Either values. If both are Right then combine both B values using combineRight or if both are Left then combine both A values using combineLeft, otherwise return the sole Left value (either this or other).

Link copied to clipboard
operator fun <A : Comparable<A>, B : Comparable<B>> Either<A, B>.compareTo(other: Either<A, B>): Int
Link copied to clipboard
inline fun <A, B, C> Either<A, B>.flatMap(f: (right: B) -> Either<A, C>): Either<A, C>

Binds the given function across Right, that is, Map, or transform, the right value B of this Either into a new Either with a right value of type C. Returns a new Either with either the original left value of type A or the newly transformed right value of type C.

Link copied to clipboard
fun <A, B> Either<A, Either<A, B>>.flatten(): Either<A, B>
Link copied to clipboard
inline fun <C> fold(ifLeft: (left: Nothing) -> C, ifRight: (right: B) -> C): C

Transform an Either into a value of C. Alternative to using when to fold an Either into a value C.

Link copied to clipboard
infix inline fun <A, B> Either<A, B>.getOrElse(default: (A) -> B): B

Get the right value B of this Either, or compute a default value with the left value A.

Link copied to clipboard

Transforms Either into Option, where the encapsulated value B is wrapped in Some when this instance represents Either.Right, or None if it is Either.Left.

Link copied to clipboard
fun getOrNull(): B?

Returns the unwrapped value B of Either.Right or null if it is Either.Left.

Link copied to clipboard
fun <A, B, C> Either<A, B>.handleErrorWith(f: (A) -> Either<C, B>): Either<C, B>

Binds the given function across Left, that is, Map, or transform, the left value A of this Either into a new Either with a left value of type C. Returns a new Either with either the original right value of type B or the newly transformed left value of type C.

Link copied to clipboard

Returns true if this is a Left, false otherwise.

inline fun isLeft(predicate: (Nothing) -> Boolean): Boolean

Returns false if Right or returns the result of the given predicate to the Left value.

Link copied to clipboard

Returns true if this is a Right, false otherwise.

inline fun isRight(predicate: (B) -> Boolean): Boolean

Returns false if Left or returns the result of the given predicate to the Right value.

Link copied to clipboard

Returns the unwrapped value A of Either.Left or null if it is Either.Right.

Link copied to clipboard
inline fun <C> map(f: (right: B) -> C): Either<Nothing, C>

Map, or transform, the right value B of this Either to a new value C.

Link copied to clipboard
inline fun <C> mapLeft(f: (Nothing) -> C): Either<C, B>

Map, or transform, the left value A of this Either to a new value C.

Link copied to clipboard
fun <A> Either<A, A>.merge(): A

Returns the value from this Right or Left.

Link copied to clipboard
inline fun onLeft(action: (left: Nothing) -> Unit): Either<Nothing, B>

Performs the given action on the encapsulated A if this instance represents Either.Left. Returns the original Either unchanged.

Link copied to clipboard
inline fun onRight(action: (right: B) -> Unit): Either<Nothing, B>

Performs the given action on the encapsulated B value if this instance represents Either.Right. Returns the original Either unchanged.

Link copied to clipboard
inline fun <E, EE, A> Either<E, A>.recover(recover: Raise<EE>.(E) -> A): Either<EE, A>

Recover from any Either.Left if encountered.

Link copied to clipboard
fun swap(): Either<B, Nothing>

Swap the generic parameters A and B of this Either.

Link copied to clipboard
fun <E, A> Either<E, A>.toEitherNel(): EitherNel<E, A>
Link copied to clipboard
fun toIor(): Ior<Nothing, B>
Link copied to clipboard
open override fun toString(): String