Either

sealed interface Either<out L, out R>

Represents a value which may be one of two possible types: L or R. An instance of this type will be either Left or Right.

By convention Either is right-biased, meaning that Right values are the default values to operate on (e.g., via map) and Left value are typically unmodified. This lends itself to using R/Right for values which may require more processing and using L/Left for values which are relatively "final".

Parameters

L

The type of Left values

R

The type of Right values

Inheritors

Types

Link copied to clipboard
object Companion
Link copied to clipboard
interface Left<out L> : Either<L, Nothing>

The left side of an Either

Link copied to clipboard
interface Right<out R> : Either<Nothing, R>

The right side of an Either

Inherited functions

Link copied to clipboard
inline fun <L, R, T> Either<L, R>.fold(ifLeft: (left: L) -> T, ifRight: (right: R) -> T): T

Transform this Either into a value of type T via specialized mapping functions for both left and right values

Link copied to clipboard
inline fun <L, R, R2> Either<L, R>.map(func: (right: R) -> R2): Either<L, R2>

Map the right value of this Either to a new value. Left values are unmodified.

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

Returns the left value or right value