Either

sealed class Either<out L, out R>

Represents a value of one of two possible types (a disjoint union). Instances of Either are either an instance of Left or Right. FP Convention dictates that Left is used for "failure" and Right is used for "success".

See also

Inheritors

Types

Link copied to clipboard
data class Left<out L>(val a: L) : Either<L, Nothing>
Link copied to clipboard
data class Right<out R>(val b: R) : Either<Nothing, R>

Properties

Link copied to clipboard

Returns true if this is a Left, false otherwise.

Link copied to clipboard

Returns true if this is a Right, false otherwise.

Functions

Link copied to clipboard
fun <T, L, R> Either<L, R>.flatMap(fn: (R) -> Either<L, T>): Either<L, T>

Right-biased flatMap() FP convention which means that Right is assumed to be the default case to operate on. If it is Left, operations like map, flatMap, ... return the Left value unchanged.

Link copied to clipboard
fun fold(fnL: (L) -> Any, fnR: (R) -> Any): Any

Applies fnL if this is a Left or fnR if this is a Right.

Link copied to clipboard
fun <L, R> Either<L, R>.getOrElse(value: R): R

Returns the value from this Right or the given argument if this is a Left. Right(12).getOrElse(17) RETURNS 12 and Left(12).getOrElse(17) RETURNS 17

Link copied to clipboard
fun <L> left(a: L): Either.Left<L>

Creates a Left type.

Link copied to clipboard
fun <T, L, R> Either<L, R>.map(fn: (R) -> T): Either<L, T>

Right-biased map() FP convention which means that Right is assumed to be the default case to operate on. If it is Left, operations like map, flatMap, ... return the Left value unchanged.

Link copied to clipboard
fun <R> right(b: R): Either.Right<R>

Creates a Left type.