arrow-core-data / arrow.core / Ior

Ior

sealed class Ior<out A, out B> : IorOf<A, 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<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

Both data class Both<out A, out B> : Ior<A, B>
Left data class Left<out A> : Ior<A, Nothing>
Right data class Right<out B> : Ior<Nothing, B>

Properties

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

Functions

all fun all(predicate: (B) -> Boolean): Boolean
bicrosswalk fun <C, D> bicrosswalk(fa: (A) -> Iterable<C>, fb: (B) -> Iterable<D>): List<Ior<C, D>>
bicrosswalkMap fun <C, D, K> bicrosswalkMap(fa: (A) -> Map<K, C>, fb: (B) -> Map<K, D>): Map<K, Ior<C, D>>
bicrosswalkNull fun <C, D> bicrosswalkNull(fa: (A) -> C?, fb: (B) -> D?): Ior<C, D>?
bifoldLeft fun <C> bifoldLeft(c: C, f: (C, A) -> C, g: (C, B) -> C): C
bifoldMap fun <C> bifoldMap(MN: Monoid<C>, f: (A) -> C, g: (B) -> C): C
bifoldRight fun <C> ~~bifoldRight~~(c: Eval<C>, f: (A, Eval<C>) -> Eval<C>, g: (B, Eval<C>) -> Eval<C>): Eval<C>
bimap Apply fa if this is a Left or Both to A and apply fb if this is Right or Both to Bfun <C, D> bimap(fa: (A) -> C, fb: (B) -> D): Ior<C, D>
bitraverse fun <AA, C> bitraverse(fa: (A) -> Iterable<AA>, fb: (B) -> Iterable<C>): List<Ior<AA, C>>
bitraverseEither fun <AA, C, D> bitraverseEither(fa: (A) -> Either<AA, C>, fb: (B) -> Either<AA, D>): Either<AA, Ior<C, D>>
bitraverseValidated fun <AA, C, D> bitraverseValidated(SA: Semigroup<AA>, fa: (A) -> Validated<AA, C>, fb: (B) -> Validated<AA, D>): Validated<AA, Ior<C, D>>
crosswalk fun <C> crosswalk(fa: (B) -> Iterable<C>): List<Ior<A, C>>
crosswalkMap fun <K, V> crosswalkMap(fa: (B) -> Map<K, V>): Map<K, Ior<A, V>>
crosswalkNull fun <A, B, C> crosswalkNull(ior: Ior<A, B>, fa: (B) -> C?): Ior<A, C>?
exists Returns false if Left or returns the result of the application of the given predicate to the Right value.fun exists(predicate: (B) -> Boolean): Boolean
findOrNull fun findOrNull(predicate: (B) -> Boolean): B?
fold Applies fa if this is a Left, fb if this is a Right or fab if this is a Bothfun <C> fold(fa: (A) -> C, fb: (B) -> C, fab: (A, B) -> C): C
foldLeft fun <C> foldLeft(c: C, f: (C, B) -> C): C
foldMap fun <C> foldMap(MN: Monoid<C>, f: (B) -> C): C
foldRight fun <C> ~~foldRight~~(lc: Eval<C>, f: (B, Eval<C>) -> Eval<C>): Eval<C>
isEmpty fun isEmpty(): Boolean
isNotEmpty fun isNotEmpty(): Boolean
leftOrNull Returns the Left value or A if this is Left or Both and null if this is a Right.fun leftOrNull(): A?
map The given function is applied if this is a Right or Both to B.fun <D> map(f: (B) -> D): Ior<A, D>
mapLeft The given function is applied if this is a Left or Both to A.fun <C> mapLeft(fa: (A) -> C): Ior<C, B>
orNull Returns the Right value or B if this is Right or Both and null if this is a Left.fun orNull(): B?
pad Return this Ior as Pair of Optionfun ~~pad~~(): Pair<Option<A>, Option<B>>
padNull Return this Ior as Pair of nullables]fun padNull(): Pair<A?, B?>
show fun ~~show~~(SL: Show<A>, SR: Show<B>): String
swap If this is a Left, then return the left value in Right or vice versa, when this is Both , left and right values are swapfun swap(): Ior<B, A>
toEither Returns a Either.Right containing the Right value or B if this is Right or Both and Either.Left if this is a Left.fun toEither(): Either<A, B>
toLeftOption Returns a Some containing the Left value or A if this is Left or Both and None if this is a Right.fun ~~toLeftOption~~(): Option<A>
toOption Returns a Some containing the Right value or B if this is Right or Both and None if this is a Left.fun ~~toOption~~(): Option<B>
toString open fun toString(): String
toValidated Returns a Validated.Valid containing the Right value or B if this is Right or Both and Validated.Invalid if this is a Left.fun toValidated(): Validated<A, B>
traverse fun <G, C> ~~traverse~~(GA: Applicative<G>, f: (B) -> Kind<G, C>): Kind<G, Ior<A, C>>
fun <C> traverse(fa: (B) -> Iterable<C>): List<Ior<A, C>>
traverseEither fun <AA, C> traverseEither(fa: (B) -> Either<AA, C>): Either<AA, Ior<A, C>>
traverseValidated fun <AA, C> traverseValidated(fa: (B) -> Validated<AA, C>): Validated<AA, Ior<A, C>>
unwrap Return the isomorphic Either of this Iorfun unwrap(): Either<Either<A, B>, Pair<A, B>>
void fun void(): Ior<A, Unit>

Companion Object Functions

bothNel fun <A, B> bothNel(a: A, b: B): IorNel<A, B>
fromNullables Create an Ior from two nullables if at least one of them is defined.fun <A, B> fromNullables(a: A?, b: B?): Ior<A, B>?
fromOptions Create an Ior from two Options if at least one of them is defined.fun <A, B> ~~fromOptions~~(oa: Option<A>, ob: Option<B>): Option<Ior<A, B>>
leftNel fun <A, B> leftNel(a: A): IorNel<A, B>
lift Lifts a function (B) -> C to the Ior structure returning a polymorphic function that can be applied over all Ior values in the shape of Ior<A, B>fun <A, B, C> lift(f: (B) -> C): (Ior<A, B>) -> Ior<A, C>fun <A, B, C, D> lift(fa: (A) -> C, fb: (B) -> D): (Ior<A, B>) -> Ior<C, D>
tailRecM fun <L, A, B> ~~tailRecM~~(a: A, f: (A) -> IorOf<L, Either<A, B>>, SL: Semigroup<L>): Ior<L, B>

Extension Functions

altFold fun <T, F, A> Kind<T, A>.altFold(AF: Alternative<F>, FT: Foldable<T>): Kind<F, A>
altSum fun <T, F, A> Kind<T, Kind<F, A>>.altSum(AF: Alternative<F>, FT: Foldable<T>): Kind<F, A>
ap fun <A, B, D> Ior<A, B>.~~ap~~(SG: Semigroup<A>, ff: IorOf<A, (B) -> D>): Ior<A, D>
bisequence fun <A, B> Ior<Iterable<A>, Iterable<B>>.bisequence(): List<Ior<A, B>>
bisequenceEither fun <A, B, C> Ior<Either<A, B>, Either<A, C>>.bisequenceEither(): Either<A, Ior<B, C>>
bisequenceValidated fun <A, B, C> Ior<Validated<A, B>, Validated<A, C>>.bisequenceValidated(SA: Semigroup<A>): Validated<A, Ior<B, C>>
combine fun <A, B> Ior<A, B>.combine(SA: Semigroup<A>, SB: Semigroup<B>, other: Ior<A, B>): Ior<A, B>
compareTo operator fun <A : Comparable<A>, B : Comparable<B>> Ior<A, B>.compareTo(other: Ior<A, B>): Int
conest fun <F, A, B> CounnestedType<F, A, B>.conest(): ConestedType<F, A, B>
fix fun <A, B> IorOf<A, B>.~~fix~~(): Ior<A, B>
flatMap Binds the given function across Ior.Right.fun <A, B, D> Ior<A, B>.flatMap(SG: Semigroup<A>, f: (B) -> Ior<A, D>): Ior<A, D>
flatten fun <A, B> Ior<A, Ior<A, B>>.flatten(SA: Semigroup<A>): Ior<A, B>
getOrElse fun <A, B> Ior<A, B>.getOrElse(default: () -> B): B
leftWiden fun <AA, A : AA, B> Ior<A, B>.leftWiden(): Ior<AA, B>
replicate 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 fun <A, B> Ior<A, Iterable<B>>.sequence(): List<Ior<A, B>>
fun <A, B, G> IorOf<A, Kind<G, B>>.~~sequence~~(GA: Applicative<G>): Kind<G, Ior<A, B>>
sequenceEither fun <A, B, C> Ior<A, Either<B, C>>.sequenceEither(): Either<B, Ior<A, C>>
sequenceValidated fun <A, B, C> Ior<A, Validated<B, C>>.sequenceValidated(): Validated<B, Ior<A, C>>
widen Given B is a sub type of C, re-type this value from Ior<A, B> to Ior<A, B>fun <A, C, B : C> Ior<A, B>.widen(): Ior<A, C>
zip fun <A, B, C> Ior<A, B>.zip(SA: Semigroup<A>, fb: Ior<A, C>): Ior<A, Pair<B, C>>
fun <A, B, C, D> Ior<A, B>.zip(SA: Semigroup<A>, c: Ior<A, C>, map: (B, C) -> D): Ior<A, D>
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>
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>
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>
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>
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>
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>
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>
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
<