Either

@Serializable(with = EitherSerializer::class)
sealed class Either<out L, out R>

Base implementation. Can either be Left or Right.

Inheritors

Properties

Link copied to clipboard
abstract val left: L

Underlying value on the Left implementation

Link copied to clipboard
abstract val leftOrNull: L?
Link copied to clipboard
abstract val right: R

Underlying value on the Right implementation

Link copied to clipboard
abstract val rightOrNull: R?

Functions

Link copied to clipboard
inline fun <L, R> Either<L, R>.alsoBoth(onLeft: (L) -> Unit, onRight: (R) -> Unit): Either<L, R>

Depending on this kind:

Link copied to clipboard
inline fun <L, R> Either<L, R>.alsoLeft(block: (L) -> Unit): Either<L, R>

On a Left Either, calls the specified function block with Either.left

Link copied to clipboard
inline fun <L, R> Either<L, R>.alsoRight(block: (R) -> Unit): Either<L, R>

On a Right Either, calls the specified function block with Either.right.

Link copied to clipboard
inline fun <L, R, NewType> Either<L, R>.foldBoth(onLeft: (L) -> NewType, onRight: (R) -> NewType): NewType

Depending on this Kind:

Link copied to clipboard
inline fun <L, R> Either<L, R>.foldLeft(block: (L) -> R): R

On a Left Either, calls the specified function block to transform Either.left into Either.right type.

Link copied to clipboard
inline fun <L, R> Either<L, R>.foldRight(block: (R) -> L): L

On a Right Either, calls the specified function block to transform Either.right into Either.left type.

Link copied to clipboard
abstract fun invert(): Either<R, L>

Swap the type of this. A Left becomes Right; A Right becomes Left.

Link copied to clipboard
abstract fun leftAsOption(): Option<L>
Link copied to clipboard
inline fun <OldL, OldR, NewL, NewR> Either<OldL, OldR>.letBoth(onLeft: (OldL) -> NewL, onRight: (OldR) -> NewR): Either<NewL, NewR>

Depending on this kind:

Link copied to clipboard
inline fun <OldL, NewL, R> Either<OldL, R>.letLeft(block: (OldL) -> NewL): Either<NewL, R>

On a Left Either, calls the specified function block to transform Either.left.

Link copied to clipboard
inline fun <L, OldR, NewR> Either<L, OldR>.letRight(block: (OldR) -> NewR): Either<L, NewR>

On a Right Either, calls the specified function block to transform Either.right.

Link copied to clipboard
inline fun <L, R> Either<L, R>.requireLeft(block: (Right<R>) -> Nothing): L

Try to get Either.left or calls block to return or stops the current execution block.

Link copied to clipboard
inline fun <L, R> Either<L, R>.requireRight(block: (Left<L>) -> Nothing): R

Try to get Either.right or calls block to return or stops the current execution block.

Link copied to clipboard
abstract fun rightAsOption(): Option<R>
Link copied to clipboard
infix inline fun <OldL, NewL, R> Either<OldL, R>.tryLeft(block: (OldL) -> Either<NewL, R>): Either<NewL, R>

Depending on this Kind:

Link copied to clipboard
infix inline fun <L, OldR, NewR> Either<L, OldR>.tryRight(block: (OldR) -> Either<L, NewR>): Either<L, NewR>

Depending on this Kind: