//arrow-core/arrow.core/Ior

Ior

common sealed class Ior<out A, out B>

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.Left](-left/index.html) <`A`>
  • [Ior.Right](-right/index.html) <`B`>
  • [Ior.Both](-both/index.html)<`A`,`B`>

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 [Semigroup]<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.

Types

Name Summary
Both common data class Both<out A, out B>(leftValue: A, rightValue: B) : Ior<A, B>
Companion common object Companion
Left common data class Left<out A>(value: A) : Ior<A, Nothing>
Right common data class Right<out B>(value: B) : Ior<Nothing, B>

Functions

Name Summary
all common inline fun all(predicate: (B) -> Boolean): Boolean
bicrosswalk common inline fun <C, D> bicrosswalk(fa: (A) -> Iterable<C>, fb: (B) -> Iterable<D>): List<Ior<C, D»
bicrosswalkMap common inline fun <C, D, K> bicrosswalkMap(fa: (A) -> Map<K, C>, fb: (B) -> Map<K, D>): Map<K, Ior<C, D»
bicrosswalkNull common inline fun <C, D> bicrosswalkNull(fa: (A) -> C?, fb: (B) -> D?): Ior<C, D>?
bifoldLeft common inline fun <C> bifoldLeft(c: C, f: (C, A) -> C, g: (C, B) -> C): C
bifoldMap common inline fun <C> bifoldMap(MN: Monoid<C>, f: (A) -> C, g: (B) -> C): C
bimap common inline fun <C, D> bimap(fa: (A) -> C, fb: (B) -> D): Ior<C, D>
Apply fa if this is a Left or Both to A and apply fb if this is Right or Both to BExample:Ior.Right(12).bimap ({ "flower" }, { 12 }) // Result: Right(12) Ior.Left(12).bimap({ "flower" }, { 12 }) // Result: Left("flower") Ior.Both(12, "power").bimap ({ a, b -> "flower $b" },{ a * 2}) // Result: Both("flower power", 24)
bitraverse common inline fun <AA, C> bitraverse(fa: (A) -> Iterable<AA>, fb: (B) -> Iterable<C>): List<Ior<AA, C»
bitraverseEither common inline fun <AA, C, D> bitraverseEither(fa: (A) -> Either<AA, C>, fb: (B) -> Either<AA, D>): Either<AA, Ior<C, D»
bitraverseOption common inline fun <C, D> bitraverseOption(fa: (A) -> Option<C>, fb: (B) -> Option<D>): Option<Ior<C, D»
bitraverseValidated common inline fun <AA, C, D> bitraverseValidated(SA: Semigroup<AA>, fa: (A) -> Validated<AA, C>, fb: (B) -> Validated<AA, D>): Validated<AA, Ior<C, D»
crosswalk common inline fun <C> crosswalk(fa: (B) -> Iterable<C>): List<Ior<A, C»
crosswalkMap common inline fun <K, V> crosswalkMap(fa: (B) -> Map<K, V>): Map<K, Ior<A, V»
crosswalkNull common inline fun <A, B, C> crosswalkNull(ior: Ior<A, B>, fa: (B) -> C?): Ior<A, C>?
exists common inline fun exists(predicate: (B) -> Boolean): Boolean
Returns false if Left or returns the result of the application of the given predicate to the Right value.
findOrNull common inline fun findOrNull(predicate: (B) -> Boolean): B?
fold common 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 BothExample:val result: Ior<EmailContactInfo, PostalContactInfo> = obtainContactInfo() result.fold( { log("only have this email info: $it") }, { log("only have this postal info: $it") }, { email, postal -> log("have this postal info: $postal and this email info: $email") } )
foldLeft common inline fun <C> foldLeft(c: C, f: (C, B) -> C): C
foldMap common inline fun <C> foldMap(MN: Monoid<C>, f: (B) -> C): C
isEmpty common fun isEmpty(): Boolean
isNotEmpty common fun isNotEmpty(): Boolean
leftOrNull common fun leftOrNull(): A?
Returns the Left value or A if this is Left or Both and null if this is a Right.
map common inline fun <D> map(f: (B) -> D): Ior<A, D>
The given function is applied if this is a Right or Both to B.
mapLeft common inline fun <C> mapLeft(fa: (A) -> C): Ior<C, B>
The given function is applied if this is a Left or Both to A.
orNull common fun orNull(): B?
Returns the Right value or B if this is Right or Both and null if this is a Left.
padNull common fun padNull(): Pair<A?, B?>
Return this Ior as Pair of nullables]Example:kotlin:ank:playground import arrow.core.Ior<br>//sampleStart val right = Ior.Right(12).padNull() // Result: Pair(null, 12) val left = Ior.Left(12).padNull() // Result: Pair(12, null) val both = Ior.Both("power", 12).padNull() // Result: Pair("power", 12) //sampleEnd<br>fun main() { println("right = $right") println("left = $left") println("both = $both") }
swap common 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 swapExample:Left("left").swap() // Result: Right("left") Right("right").swap() // Result: Left("right") Both("left", "right").swap() // Result: Both("right", "left")
toEither common 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.
toString common open override fun toString(): String
toValidated common fun toValidated(): Validated<A, B>
Returns a Validated.Valid containing the Right value or B if this is Right or Both and Validated.Invalid if this is a Left.
traverse common inline fun <C> traverse(fa: (B) -> Iterable<C>): List<Ior<A, C»
traverseEither common inline fun <AA, C> traverseEither(fa: (B) -> Either<AA, C>): Either<AA, Ior<A, C»
traverseOption common inline fun <C> traverseOption(fa: (B) -> Option<C>): Option<Ior<A, C»
traverseValidated common inline fun <AA, C> traverseValidated(fa: (B) -> Validated<AA, C>): Validated<AA, Ior<A, C»
unwrap common fun unwrap(): Either<Either<A, B>, Pair<A, B»
Return the isomorphic Either of this Ior
void common fun void(): Ior<A, Unit>

Properties

Name Summary
isBoth common abstract val isBoth: Boolean
Returns true if this is a Both, false otherwise.
isLeft common abstract val isLeft: Boolean
Returns true if this is a Left, false otherwise.
isRight common abstract val isRight: Boolean
Returns true if this is a Right, false otherwise.

Inheritors

Name
Ior
Ior
Ior

Extensions

Name Summary
bisequence common fun <A, B> Ior<Iterable<A>, Iterable<B».bisequence(): List<Ior<A, B»
bisequenceEither common fun <A, B, C> Ior<Either<A, B>, Either<A, C».bisequenceEither(): Either<A, Ior<B, C»
bisequenceOption common fun <B, C> Ior<Option<B>, Option<C».bisequenceOption(): Option<Ior<B, C»
bisequenceValidated common fun <A, B, C> Ior<Validated<A, B>, Validated<A, C».bisequenceValidated(SA: Semigroup<A>): Validated<A, Ior<B, C»
combine common fun <A, B> Ior<A, B>.combine(SA: Semigroup<A>, SB: Semigroup<B>, other: Ior<A, B>): Ior<A, B>
compareTo common operator fun <A : Comparable<A>, B : Comparable<B» Ior<A, B>.compareTo(other: Ior<A, B>): Int
flatMap common inline fun <A, B, D> Ior<A, B>.flatMap(SG: Semigroup<A>, f: (B) -> Ior<A, D>): Ior<A, D>
Binds the given function across Ior.Right.
flatten common inline fun <A, B> Ior<A, Ior<A, B».flatten(SA: Semigroup<A>): Ior<A, B>
getOrElse common inline fun <A, B> Ior<A, B>.getOrElse(default: () -> B): B
leftWiden common fun <AA, A : AA, B> Ior<A, B>.leftWiden(): Ior<AA, B>
replicate common fun <A, B> Ior<A, B>.replicate(SA: Semigroup<A>, n: Int): Ior<A, List<B»
fun <A, B> Ior<A, B>.replicate(SA: Semigroup<A>, n: Int, MB: Monoid<B>): Ior<A, B>
sequence common fun <A, B> Ior<A, Iterable<B».sequence(): List<Ior<A, B»
sequenceEither common fun <A, B, C> Ior<A, Either<B, C».sequenceEither(): Either<B, Ior<A, C»
sequenceOption common fun <A, B> Ior<A, Option<B».sequenceOption(): Option<Ior<A, B»
sequenceValidated common fun <A, B, C> Ior<A, Validated<B, C».sequenceValidated(): Validated<B, Ior<A, C»
widen common fun <A, C, B : C> Ior<A, B>.widen(): Ior<A, C>
Given B is a sub type of C, re-type this value from Ior<A, B> to Ior<A, B>kotlin:ank:playground:extension import arrow.core.*<br>fun main(args: Array<String>) { //sampleStart val string: Ior<Int, String> = Ior.Right("Hello") val chars: Ior<Int, CharSequence> = string.widen<Int, CharSequence, String>() //sampleEnd println(chars) }
zip common fun <A, B, C> Ior<A, B>.zip(SA: Semigroup<A>, fb: Ior<A, C>): Ior<A, Pair<B, C»
inline fun <A, B, C, D> Ior<A, B>.zip(SA: Semigroup<A>, c: Ior<A, C>, map: (B, C) -> D): Ior<A, D>
inline fun <A, B, C, D, E> Ior<A, B>.zip(SA: Semigroup<A>, c: Ior<A, C>, d: Ior<A, D>, map: (B, C, D) -> E): Ior<A, E>
inline fun <A, B, C, D, E, F> Ior<A, B>.zip(SA: Semigroup<A>, c: Ior<A, C>, d: Ior<A, D>, e: Ior<A, E>, map: (B, C, D, E) -> F): Ior<A, F>
inline fun <A, B, C, D, E, F, G> Ior<A, B>.zip(SA: Semigroup<A>, c: Ior<A, C>, d: Ior<A, D>, e: Ior<A, E>, f: Ior<A, F>, map: (B, C, D, E, F) -> G): Ior<A, G>
inline fun <A, B, C, D, E, F, G, H> Ior<A, B>.zip(SA: Semigroup<A>, c: Ior<A, C>, d: Ior<A, D>, e: Ior<A, E>, f: Ior<A, F>, g: Ior<A, G>, map: (B, C, D, E, F, G) -> H): Ior<A, H>
inline fun <A, B, C, D, E, F, G, H, I> Ior<A, B>.zip(SA: Semigroup<A>, c: Ior<A, C>, d: Ior<A, D>, e: Ior<A, E>, f: Ior<A, F>, g: Ior<A, G>, h: Ior<A, H>, map: (B, C, D, E, F, G, H) -> I): Ior<A, I>
inline fun <A, B, C, D, E, F, G, H, I, J> Ior<A, B>.zip(SA: Semigroup<A>, c: Ior<A, C>, d: Ior<A, D>, e: Ior<A, E>, f: Ior<A, F>, g: Ior<A, G>, h: Ior<A, H>, i: Ior<A, I>, map: (B, C, D, E, F, G, H, I) -> J): Ior<A, J>
inline fun <A, B, C, D, E, F, G, H, I, J, K> Ior<A, B>.zip(SA: Semigroup<A>, c: Ior<A, C>, d: Ior<A, D>, e: Ior<A, E>, f: Ior<A, F>, g: Ior<A, G>, h: Ior<A, H>, i: Ior<A, I>, j: Ior<A, J>, map: (B, C, D, E, F, G, H, I, J) -> K): Ior<A, K>
inline fun <A, B, C, D, E, F, G, H, I, J, K, L> Ior<A, B>.zip(SA: Semigroup<A>, c: Ior<A, C>, d: Ior<A, D>, e: Ior<A, E>, f: Ior<A, F>, g: Ior<A, G>, h: Ior<A, H>, i: Ior<A, I>, j: Ior<A, J>, k: Ior<A, K>, map: (B, C, D, E, F, G, H, I, J, K) -> L): Ior<A, L>

Do you like Arrow?

Arrow Org
<