Packages

sealed abstract class Ior[+A, +B] extends Product with Serializable

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

An instance of A Ior B is one of:

A Ior B is similar to scala.util.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 Both values using a Semigroup[A], while other methods, like toEither, ignore the A value in a Both.

A Ior B is isomorphic to Either[Either[A, B], (A, B)], but provides methods biased toward B values, regardless of whether the B values appear in a Right or a Both. The isomorphic scala.util.Either form can be accessed via the unwrap method.

Source
Ior.scala
Linear Supertypes
Known Subclasses
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Ior
  2. Serializable
  3. Serializable
  4. Product
  5. Equals
  6. AnyRef
  7. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def canEqual(that: Any): Boolean
    Definition Classes
    Equals
  2. abstract def productArity: Int
    Definition Classes
    Product
  3. abstract def productElement(n: Int): Any
    Definition Classes
    Product

Concrete Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def ===[AA >: A, BB >: B](that: Ior[AA, BB])(implicit AA: Eq[AA], BB: Eq[BB]): Boolean
  5. final def addLeft[AA >: A](left: AA)(implicit AA: Semigroup[AA]): Ior[AA, B]

    When a Left value is present in the Ior, combine it will the value specified.

    When a Left value is present in the Ior, combine it will the value specified.

    When the Left value is absent, set it to the value specified.

    Example:

    scala> import cats.data.Ior
    scala> import cats.implicits._
    
    scala> val ior1 = "abc".leftIor[Int]
    scala> ior1.addLeft("def")
    res0: Ior[String, Int] = Left(abcdef)
    
    scala> val ior2 = 123.rightIor[String]
    scala> ior2.addLeft("abc")
    res1: cats.data.Ior[String,Int] = Both(abc,123)
    
    scala> val ior3 = Ior.Both("abc",123)
    scala> ior3.addLeft("def")
    res2: Ior[String, Int] = Both(abcdef,123)
  6. final def addRight[BB >: B](right: BB)(implicit BB: Semigroup[BB]): Ior[A, BB]

    When a Right value is present in the Ior, combine it will the value specified.

    When a Right value is present in the Ior, combine it will the value specified.

    When the Right value is absent, set it to the value specified.

    Example:

    scala> import cats.data.Ior
    scala> import cats.implicits._
    
    scala> val ior1 = "abc".leftIor[Int]
    scala> ior1.addRight(123)
    res0: Ior[String, Int] = Both(abc,123)
    
    scala> val ior2 = 123.rightIor[String]
    scala> ior2.addRight(123)
    res1: Ior[String, Int] = Right(246)
    
    scala> val ior3 = Ior.Both("abc",123)
    scala> ior3.addRight(123)
    res2: Ior[String, Int] = Both(abc,246)
  7. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  8. final def bimap[C, D](fa: (A) ⇒ C, fb: (B) ⇒ D): Ior[C, D]

    Example:

    Example:

    scala> import cats.data.Ior
    scala> import cats.implicits._
    
    scala> "abc".leftIor[Int].bimap(_.length, identity)
    res0: Ior[Int, Int] = Left(3)
    
    scala> 123.rightIor[String].bimap(_.length, identity)
    res1: Ior[Int, Int] = Right(123)
    
    scala> Ior.Both("abc", 123).bimap(_.length, identity)
    res2: Ior[Int, Int] = Both(3,123)
  9. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native() @IntrinsicCandidate()
  10. final def combine[AA >: A, BB >: B](that: Ior[AA, BB])(implicit AA: Semigroup[AA], BB: Semigroup[BB]): Ior[AA, BB]

    Example:

    Example:

    scala> import cats.data.Ior
    scala> import cats.implicits._
    
    scala> "abc".leftIor[Int].combine("other".leftIor[Int])
    res0: Ior[String, Int] = Left(abcother)
    
    scala> "abc".leftIor[Int].combine(456.rightIor[String])
    res1: Ior[String, Int] = Both(abc,456)
    
    scala> 123.rightIor[String].combine("other".leftIor[Int])
    res2: Ior[String, Int] = Both(other,123)
    
    scala> Ior.Both("abc", 123).combine(Ior.Both("other",456))
    res3: Ior[String, Int] = Both(abcother,579)
    
    scala> Ior.Both("abc", 123).combine("other".leftIor[Int])
    res3: Ior[String, Int] = Both(abcother,123)
    
    scala> Ior.Both("abc", 123).combine(456.rightIor[String])
    res3: Ior[String, Int] = Both(abc,579)
  11. final def compare[AA >: A, BB >: B](that: Ior[AA, BB])(implicit AA: Order[AA], BB: Order[BB]): Int
  12. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  13. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  14. final def exists(p: (B) ⇒ Boolean): Boolean

    Example:

    Example:

    scala> import cats.data.Ior
    scala> import cats.implicits._
    
    scala> "abc".leftIor[Int].exists(_ > 100)
    res0: Boolean = false
    
    scala> 123.rightIor[String].exists(_ > 100)
    res1: Boolean = true
    
    scala> Ior.Both("abc", 123).exists(_ > 100)
    res2: Boolean = true
  15. final def flatMap[AA >: A, D](f: (B) ⇒ Ior[AA, D])(implicit AA: Semigroup[AA]): Ior[AA, D]

    Example:

    Example:

    scala> import cats.data.Ior
    scala> import cats.implicits._
    
    scala> "abc".leftIor[Int].flatMap(i => 456.rightIor[String])
    res0: Ior[String, Int] = Left(abc)
    
    scala> 123.rightIor[String].flatMap(i => (i * 2).rightIor[String])
    res1: Ior[String, Int] = Right(246)
    
    scala> 123.rightIor[String].flatMap(_ => "error".leftIor[Int])
    res2: Ior[String, Int] = Left(error)
    
    scala> Ior.Both("abc", 123).flatMap(_ => 456.rightIor[String])
    res3: Ior[String, Int] = Both(abc,456)
    
    scala> Ior.Both("abc", 123).flatMap(_ => "error".leftIor[Int])
    res4: Ior[String, Int] = Left(abcerror)
    
    scala> Ior.Both("abc", 123).flatMap(_ => Ior.Both("error",456))
    res5: Ior[String, Int] = Both(abcerror,456)
  16. final def fold[C](fa: (A) ⇒ C, fb: (B) ⇒ C, fab: (A, B) ⇒ C): C

    Example:

    Example:

    scala> import cats.data.Ior
    scala> import cats.implicits._
    
    scala> val rightF: Int => String = _.show
    scala> val bothF: (String,Int) => String = (a,b) => a.combine(b.show)
    
    scala> val ior1 = "abc".leftIor[Int]
    scala> ior1.fold(identity, rightF, bothF)
    res0: String = abc
    
    scala> val ior2 = 123.rightIor[String]
    scala> ior2.fold(identity, rightF, bothF)
    res1: String = 123
    
    scala> val ior3 = Ior.Both("abc", 123)
    scala> ior3.fold(identity, rightF, bothF)
    res2: String = abc123
  17. final def foldLeft[C](c: C)(f: (C, B) ⇒ C): C

    Example:

    Example:

    scala> import cats.data.Ior
    scala> import cats.implicits._
    
    scala> "abc".leftIor[Int].foldLeft(List(456))((c,b) => b :: c)
    res0: List[Int] = List(456)
    
    scala> 123.rightIor[String].foldLeft(List(456))((c,b) => b :: c)
    res1: List[Int] = List(123, 456)
    
    scala> Ior.Both("abc", 123).foldLeft(List(456))((c,b) => b :: c)
    res2: List[Int] = List(123, 456)
  18. final def foldRight[C](lc: Eval[C])(f: (B, Eval[C]) ⇒ Eval[C]): Eval[C]
  19. final def forall(p: (B) ⇒ Boolean): Boolean

    Example:

    Example:

    scala> import cats.data.Ior
    scala> import cats.implicits._
    
    scala> "abc".leftIor[Int].forall(_ > 100)
    res0: Boolean = true
    
    scala> 123.rightIor[String].forall(_ > 150)
    res1: Boolean = false
    
    scala> Ior.Both("abc", 123).forall(_ > 100)
    res2: Boolean = true
  20. final def foreach(f: (B) ⇒ Unit): Unit

    Example:

    Example:

    scala> import cats.data.Ior
    scala> import cats.implicits._
    
    // Nothing to show
    scala> "abc".leftIor[Int].foreach(println)
    res0: Unit = ()
    
    // 123 to be shown
    scala> 123.rightIor[String].foreach(println)
    res1: Unit = ()
    
    123 to be shown
    scala> Ior.both("abc", 123).foreach(println)
    res2: Unit = ()
  21. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @IntrinsicCandidate()
  22. final def getOrElse[BB >: B](bb: ⇒ BB): BB

    Example:

    Example:

    scala> import cats.data.Ior
    scala> import cats.implicits._
    
    scala> "abc".leftIor[Int].getOrElse(456)
    res0: Int = 456
    
    scala> 123.rightIor[String].getOrElse(456)
    res1: Int = 123
    
    scala> Ior.Both("abc", 123).getOrElse(456)
    res2: Int = 123
  23. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @IntrinsicCandidate()
  24. final def isBoth: Boolean
  25. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  26. final def isLeft: Boolean

    Example:

    Example:

    scala> import cats.data.Ior
    scala> import cats.implicits._
    
    scala> "abc".leftIor[Int].isLeft
    res0: Boolean = true
    
    scala> 123.rightIor[String].isLeft
    res1: Boolean = false
    
    scala> Ior.Both("abc", 123).isLeft
    res2: Boolean = false
  27. final def isRight: Boolean
  28. final def left: Option[A]

    Example:

    Example:

    scala> import cats.data.Ior
    scala> import cats.implicits._
    
    scala> "abc".leftIor[Int].left
    res0: Option[String] = Some(abc)
    
    scala> 123.rightIor[String].left
    res1: Option[String] = None
    
    scala> Ior.Both("abc", 123).left
    res2: Option[String] = Some(abc)
  29. final def leftMap[C](f: (A) ⇒ C): Ior[C, B]

    Example:

    Example:

    scala> import cats.data.Ior
    scala> import cats.implicits._
    
    scala> "abc".leftIor[Int].leftMap(_.length)
    res0: Ior[Int, Int] = Left(3)
    
    scala> 123.rightIor[String].leftMap(_.length)
    res1: Ior[Int, Int] = Right(123)
    
    scala> Ior.Both("abc", 123).leftMap(_.length)
    res2: Ior[Int, Int] = Both(3,123)
  30. final def map[D](f: (B) ⇒ D): Ior[A, D]

    Example:

    Example:

    scala> import cats.data.Ior
    scala> import cats.implicits._
    
    scala> "abc".leftIor[Int].map(_ * 2)
    res0: Ior[String, Int] = Left(abc)
    
    scala> 123.rightIor[String].map(_ * 2)
    res1: Ior[String, Int] = Right(246)
    
    scala> Ior.Both("abc", 123).map(_ * 2)
    res2: Ior[String, Int] = Both(abc,246)
  31. final def merge[AA >: A](implicit ev: <:<[B, AA], AA: Semigroup[AA]): AA
  32. final def mergeLeft[AA >: A](implicit ev: <:<[B, AA]): AA
  33. final def mergeRight[AA >: A](implicit ev: <:<[B, AA]): AA
  34. final def mergeWith[AA >: A](f: (A, B) ⇒ AA)(implicit ev: <:<[B, AA]): AA
  35. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  36. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @IntrinsicCandidate()
  37. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @IntrinsicCandidate()
  38. final def onlyBoth: Option[(A, B)]

    Example:

    Example:

    scala> import cats.data.Ior
    scala> import cats.implicits._
    
    scala> "abc".leftIor[Int].onlyBoth
    res0: Option[(String, Int)] = None
    
    scala> 123.rightIor[String].onlyBoth
    res1: Option[(String, Int)] = None
    
    scala> Ior.Both("abc", 123).onlyBoth
    res2: Option[(String, Int)] = Some((abc,123))
  39. final def onlyLeft: Option[A]

    Example:

    Example:

    scala> import cats.data.Ior
    scala> import cats.implicits._
    
    scala> "abc".leftIor[Int].onlyLeft
    res0: Option[String] = Some(abc)
    
    scala> 123.rightIor[String].onlyLeft
    res1: Option[String] = None
    
    scala> Ior.Both("abc", 123).onlyLeft
    res2: Option[String] = None
  40. final def onlyLeftOrRight: Option[Either[A, B]]

    Example:

    Example:

    scala> import cats.data.Ior
    scala> import cats.implicits._
    
    scala> "abc".leftIor[Int].onlyLeftOrRight
    res0: Option[Either[String, Int]] = Some(Left(abc))
    
    scala> 123.rightIor[String].onlyLeftOrRight
    res1: Option[Either[String, Int]] = Some(Right(123))
    
    scala> Ior.Both("abc", 123).onlyLeftOrRight
    res2: Option[Either[String, Int]] = None
  41. final def onlyRight: Option[B]

    Example:

    Example:

    scala> import cats.data.Ior
    scala> import cats.implicits._
    
    scala> "abc".leftIor[Int].onlyRight
    res0: Option[Int] = None
    
    scala> 123.rightIor[String].onlyRight
    res1: Option[Int] = Some(123)
    
    scala> Ior.Both("abc", 123).onlyRight
    res2: Option[Int] = None
  42. final def pad: (Option[A], Option[B])

    Example:

    Example:

    scala> import cats.data.Ior
    scala> import cats.implicits._
    
    scala> "abc".leftIor[Int].pad
    res0: (Option[String], Option[Int]) = (Some(abc),None)
    
    scala> 123.rightIor[String].pad
    res1: (Option[String], Option[Int]) = (None,Some(123))
    
    scala> Ior.Both("abc", 123).pad
    res2: (Option[String], Option[Int]) = (Some(abc),Some(123))
  43. def productIterator: Iterator[Any]
    Definition Classes
    Product
  44. def productPrefix: String
    Definition Classes
    Product
  45. final def putLeft[C](left: C): Ior[C, B]

    Example:

    Example:

    scala> import cats.data.Ior
    scala> import cats.implicits._
    
    scala> val ior1 = "abc".leftIor[Int]
    scala> ior1.putLeft(true)
    res0: Ior[Boolean, Int] = Left(true)
    
    scala> val ior2 = 123.rightIor[String]
    scala> ior2.putLeft(false)
    res1: Ior[Boolean, Int] = Both(false,123)
    
    scala> val ior3 = Ior.Both("abc",123)
    scala> ior3.putLeft(true)
    res2: Ior[Boolean, Int] = Both(true,123)
  46. final def putRight[C](right: C): Ior[A, C]

    Example:

    Example:

    scala> import cats.data.Ior
    scala> import cats.implicits._
    
    scala> val ior1 = "abc".leftIor[Int]
    scala> ior1.putRight(123L)
    res0: Ior[String, Long] = Both(abc,123)
    
    scala> val ior2 = 123.rightIor[String]
    scala> ior2.putRight(123L)
    res1: Ior[String, Long] = Right(123)
    
    scala> val ior3 = Ior.Both("abc",123)
    scala> ior3.putRight(123L)
    res2: Ior[String, Long] = Both(abc,123)
  47. final def right: Option[B]

    Example:

    Example:

    scala> import cats.data.Ior
    scala> import cats.implicits._
    
    scala> "abc".leftIor[Int].right
    res0: Option[Int] = None
    
    scala> 123.rightIor[String].right
    res1: Option[Int] = Some(123)
    
    scala> Ior.Both("abc", 123).right
    res2: Option[Int] = Some(123)
  48. final def show[AA >: A, BB >: B](implicit AA: Show[AA], BB: Show[BB]): String
  49. final def swap: Ior[B, A]

    Example:

    Example:

    scala> import cats.data.Ior
    scala> import cats.implicits._
    
    scala> "abc".leftIor[Int].swap
    res0: Ior[Int, String] = Right(abc)
    
    scala> 123.rightIor[String].swap
    res1: Ior[Int, String] = Left(123)
    
    scala> Ior.Both("abc", 123).swap
    res2: Ior[Int, String] = Both(123,abc)
  50. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  51. final def to[F[_], BB >: B](implicit F: Alternative[F]): F[BB]

    Example:

    Example:

    scala> import cats.data.Ior
    scala> import cats.implicits._
    
    scala> "abc".leftIor[Int].to[List, Int]
    res0: List[Int] = List()
    
    scala> 123.rightIor[String].to[List, Int]
    res1: List[Int]= List(123)
    
    scala> Ior.Both("abc", 123).to[List, Int]
    res2: List[Int] = List(123)
  52. final def toEither: Either[A, B]

    Example:

    Example:

    scala> import cats.data.Ior
    scala> import cats.implicits._
    
    scala> "abc".leftIor[Int].toEither
    res0: Either[String, Int] = Left(abc)
    
    scala> 123.rightIor[String].toEither
    res1: Either[String, Int]= Right(123)
    
    scala> Ior.Both("abc", 123).toEither
    res2: Either[String, Int] = Right(123)
  53. final def toIorNec[AA >: A]: IorNec[AA, B]
  54. final def toIorNel[AA >: A]: IorNel[AA, B]

    Example:

    Example:

    scala> import cats.data.Ior
    scala> import cats.implicits._
    
    scala> "abc".leftIor[Int].toIorNel
    res0: IorNel[String, Int] = Left(NonEmptyList(abc))
    
    scala> 123.rightIor[String].toIorNel
    res1: IorNel[String, Int]= Right(123)
    
    scala> Ior.Both("abc", 123).toIorNel
    res2: IorNel[String, Int] = Both(NonEmptyList(abc),123)
  55. final def toIorNes[AA >: A](implicit O: Order[AA]): IorNes[AA, B]

    Example:

    Example:

    scala> import cats.data.Ior
    scala> import cats.implicits._
    
    scala> "abc".leftIor[Int].toIorNes
    res0: IorNes[String, Int] = Left(TreeSet(abc))
    
    scala> 123.rightIor[String].toIorNes
    res1: IorNes[String, Int]= Right(123)
    
    scala> Ior.Both("abc", 123).toIorNes
    res2: IorNes[String, Int] = Both(TreeSet(abc),123)
  56. final def toList: List[B]

    Example:

    Example:

    scala> import cats.data.Ior
    scala> import cats.implicits._
    
    scala> "abc".leftIor[Int].toList
    res0: List[Int] = List()
    
    scala> 123.rightIor[String].toList
    res1: List[Int]= List(123)
    
    scala> Ior.Both("abc", 123).toList
    res2: List[Int] = List(123)
  57. final def toOption: Option[B]

    Example:

    Example:

    scala> import cats.data.Ior
    scala> import cats.implicits._
    
    scala> "abc".leftIor[Int].toOption
    res0: Option[Int] = None
    
    scala> 123.rightIor[String].toOption
    res1: Option[Int]= Some(123)
    
    scala> Ior.Both("abc", 123).toOption
    res2: Option[Int] = Some(123)
  58. def toString(): String
    Definition Classes
    AnyRef → Any
  59. final def toValidated: Validated[A, B]

    Example:

    Example:

    scala> import cats.data.Ior
    scala> import cats.implicits._
    
    scala> "abc".leftIor[Int].toValidated
    res0: Validated[String, Int] = Invalid(abc)
    
    scala> 123.rightIor[String].toValidated
    res1: Validated[String, Int]= Valid(123)
    
    scala> Ior.Both("abc", 123).toValidated
    res2: Validated[String, Int] = Valid(123)
  60. final def traverse[F[_], AA >: A, D](g: (B) ⇒ F[D])(implicit F: Applicative[F]): F[Ior[AA, D]]

    Example

    Example

    scala> import cats.data.Ior
    scala> import cats.implicits._
    
    scala> "abc".leftIor[Int].traverse(i => List(i, i * 2))
    res0: List[Ior[String,Int]] = List(Left(abc))
    
    scala> 123.rightIor[String].traverse(i => List(i, i * 2))
    res1: List[Ior[String,Int]] = List(Right(123), Right(246))
    
    scala> Ior.both("abc", 123).traverse(i => List(i, i * 2))
    res2: List[Ior[String,Int]] = List(Both(abc,123), Both(abc,246))
  61. final def unwrap: Either[Either[A, B], (A, B)]

    Example:

    Example:

    scala> import cats.data.Ior
    scala> import cats.implicits._
    
    scala> "abc".leftIor[Int].unwrap
    res0: Either[Either[String, Int], (String, Int)] = Left(Left(abc))
    
    scala> 123.rightIor[String].unwrap
    res1: Either[Either[String, Int], (String, Int)] = Left(Right(123))
    
    scala> Ior.Both("abc", 123).unwrap
    res2: Either[Either[String, Int], (String, Int)] = Right((abc,123))
  62. final def valueOr[BB >: B](f: (A) ⇒ BB)(implicit BB: Semigroup[BB]): BB

    Example:

    Example:

    scala> import cats.data.Ior
    scala> import cats.implicits._
    
    scala> "abc".leftIor[Int].valueOr(_.length)
    res0: Int = 3
    
    scala> 123.rightIor[String].valueOr(_.length)
    res1: Int = 123
    
    scala> Ior.Both("abc", 123).valueOr(_.length)
    res2: Int = 126
  63. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  64. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  65. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Deprecated Value Members

  1. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] ) @Deprecated
    Deprecated

Inherited from Serializable

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from AnyRef

Inherited from Any

Ungrouped