Package-level declarations

Types

Link copied to clipboard
sealed class Either<out L, out R>

Important: This is a Public Preview API. It may be changed or removed at any time.

Functions

Link copied to clipboard
inline fun <L, R, T, U> Either<L, R>.bimap(fLeft: (L) -> T, fRight: (R) -> U): Either<T, U>

Map over Left and Right of this Either.

Link copied to clipboard
inline fun <L, R, R2> Either<L, R>.flatMap(fRight: (R) -> Either<L, R2>): Either<L, R2>

Binds provided function if this is Either.Right.

Link copied to clipboard
inline fun <L, R, L2> Either<L, R>.flatMapLeft(fLeft: (L) -> Either<L2, R>): Either<L2, R>

Binds provided function if this is Either.Left.

Link copied to clipboard
inline fun <L, R, T> Either<L, R>.fold(fLeft: (L) -> T, fRight: (R) -> T): T

Applies fLeft if this is Either.Left or fRight if this is Either.Right.

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

Gets right value if this is Either.Right otherwise uses provided default.

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

Gets the left value if this is Either.Right otherwise uses provided handler by providing the value from Either.Left.

Link copied to clipboard
fun <L : Throwable, R> Either<L, R>.getOrThrow(): R

Gets the left value if this is Either.Right otherwise throws from Either.Left.

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

Executes provided action if this is Either.Left.

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

Executes provided action if this is Either.Right.

Link copied to clipboard
fun <L> L.left(): Either<L, Nothing>

Wraps L into a Either.Left.

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

Wraps L into a Either.Left with specific right type.

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

Applies given function if this is Either.Right.

Link copied to clipboard
inline fun <L, R, L2> Either<L, R>.mapLeft(fLeft: (L) -> L2): Either<L2, R>

Applies given function if this is Either.Left.

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

Returns the value from this either whether its Either.Left or Either.Right.

Link copied to clipboard
fun <L, R> Either<L, R>.orNull(): R?

Gets the right value if this is Either.Right, otherwise null.

Link copied to clipboard
fun <R> R.right(): Either<Nothing, R>

Wraps R into a Either.Right.

Link copied to clipboard
inline fun <L, R> R?.rightIfNotNull(ifNull: () -> L): Either<L, R>

Wraps R into a Either.Right if it is not null, otherwise returns Either.Left.

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

Wraps R into a Either.Right with specific left type.

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

Returns left value in Either.Right if it is Either.Left or vice versa.

Link copied to clipboard

Converts kotlin's Result to Either.

Link copied to clipboard
inline fun <L, R1, R2, R3> Either<L, R1>.zipWith(either2: Either<L, R2>, fZip: (R1, R2) -> R3): Either<L, R3>
inline fun <L, R1, R2, R3, R4> Either<L, R1>.zipWith(either2: Either<L, R2>, either3: Either<L, R3>, fZip: (R1, R2, R3) -> R4): Either<L, R4>

Creates a Either.Right with result from fZip if all Eithers are right, otherwise Either.Left is returned.