Search

arrow-core-data / arrow.core / Ior

Ior

@higherkind 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<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, out B> : Ior<A, B>
Right data class Right<out A, out B> : Ior<A, 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

bifoldLeft fun <C> bifoldLeft(c: C, f: (C, A) -> C, g: (C, 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>
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
foldRight fun <C> foldRight(lc: Eval<C>, f: (B, Eval<C>) -> Eval<C>): Eval<C>
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>
pad Return this Ior as Pair of Optionfun pad(): Pair<Option<A>, Option<B>>
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>
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>>
unwrap Return the isomorphic Either of this Iorfun unwrap(): Either<Either<A, B>, Pair<A, B>>

Companion Object Functions

bothNel fun <A, B> bothNel(a: A, b: B): IorNel<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>
tailRecM fun <L, A, B> tailRecM(a: A, f: (A) -> <ERROR CLASS><L, Either<A, B>>, SL: Semigroup<L>): Ior<L, B>

Extension Functions

ap fun <A, B, D> Ior<A, B>.ap(SG: Semigroup<A>, ff: <ERROR CLASS><A, (B) -> D>): Ior<A, D>
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>
getOrElse fun <A, B> Ior<A, B>.getOrElse(default: () -> B): B