Ior

sealed class Ior<out A, out B>(source)

Port of https://github.com/typelevel/cats/blob/v0.9.0/core/src/main/scala/cats/data/Ior.scala

Represents a right-biased disjunction that is either an A, or a B, or both an A and a B.

An instance of Ior<A,B> is one of:

Ior<A,B> is similar to Either<A,B>, except that it can represent the simultaneous presence of an A and a B. It is right-biased so methods such as map and flatMap operate on the B value. Some methods, like flatMap, handle the presence of two Ior.Both values using a combine function (A, A) -> A, while other methods, like toEither, ignore the A value in a Ior.Both Both.

Ior<A,B> is isomorphic to Either<Either<A,B>, Pair<A,B>>, but provides methods biased toward B values, regardless of whether the B values appear in a Ior.Right or a Ior.Both. The isomorphic Either form can be accessed via the unwrap method.

Inheritors

Types

Link copied to clipboard
data class Both<out A, out B>(val leftValue: A, val rightValue: B) : Ior<A, B>
Link copied to clipboard
object Companion
Link copied to clipboard
data class Left<out A>(val value: A) : Ior<A, Nothing>
Link copied to clipboard
data class Right<out B>(val value: B) : Ior<Nothing, B>

Functions

Link copied to clipboard
fun <A, B> Ior<A, B>.combine(other: Ior<A, B>, combineA: (A, A) -> A, combineB: (B, B) -> B): Ior<A, B>
Link copied to clipboard
operator fun <A : Comparable<A>, B : Comparable<B>> Ior<A, B>.compareTo(other: Ior<A, B>): Int
Link copied to clipboard
inline fun <A, B, D> Ior<A, B>.flatMap(combine: (A, A) -> A, f: (B) -> Ior<A, D>): Ior<A, D>

Binds the given function across Ior.Right.

Link copied to clipboard
inline fun <A, B> Ior<A, Ior<A, B>>.flatten(combine: (A, A) -> A): Ior<A, B>
Link copied to clipboard
inline fun <C> fold(fa: (A) -> C, fb: (B) -> C, fab: (A, B) -> C): C

Applies fa if this is a Left, fb if this is a Right or fab if this is a Both

Link copied to clipboard
inline fun <A, B> Ior<A, B>.getOrElse(default: (A) -> B): B
Link copied to clipboard
fun getOrNull(): B?
Link copied to clipboard
@JvmName(name = "_isBoth")
fun isBoth(): Boolean

inline fun isBoth(leftPredicate: (A) -> Boolean, rightPredicate: (B) -> Boolean): Boolean

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

Link copied to clipboard
@JvmName(name = "_isLeft")
fun isLeft(): Boolean

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

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

Link copied to clipboard
@JvmName(name = "_isRight")
fun isRight(): Boolean

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

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

Link copied to clipboard
fun leftOrNull(): A?

Returns the Left value or A if this is Left or Both and null if this is a Right.

Link copied to clipboard
inline fun <D> map(f: (B) -> D): Ior<A, D>

The given function is applied if this is a Right or Both to B.

Link copied to clipboard
inline fun <C> mapLeft(fa: (A) -> C): Ior<C, B>

The given function is applied if this is a Left or Both to A.

Link copied to clipboard
fun swap(): Ior<B, A>

If this is a Left, then return the left value in Right or vice versa, when this is Both , left and right values are swap

Link copied to clipboard
fun toEither(): Either<A, B>

Returns a Either.Right containing the Right value or B if this is Right or Both and Either.Left if this is a Left.

Link copied to clipboard
fun <A, B> Ior<A, B>.toIorNel(): IorNel<A, B>

Given an Ior with an error type A, returns an IorNel with the same error type. Wraps the original error in a NonEmptyList so that it can be combined with an IorNel in a Raise DSL which operates on one.

Link copied to clipboard
fun toPair(): Pair<A?, B?>
Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
fun unwrap(): Either<Either<A, B>, Pair<A, B>>

Return the isomorphic Either of this Ior