Right
Value members
Inherited methods
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)
- Inherited from
- Ior
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)
- Inherited from
- Ior
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)
- Inherited from
- Ior
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)
- Inherited from
- Ior
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
- Inherited from
- Ior
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)
- Inherited from
- Ior
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
- Inherited from
- Ior
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)
- Inherited from
- Ior
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
- Inherited from
- Ior
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 = ()
- Inherited from
- Ior
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
- Inherited from
- Ior
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
- Inherited from
- Ior
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)
- Inherited from
- Ior
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)
- Inherited from
- Ior
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)
- Inherited from
- Ior
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))
- Inherited from
- Ior
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
- Inherited from
- Ior
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
- Inherited from
- Ior
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
- Inherited from
- Ior
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))
- Inherited from
- Ior
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)
- Inherited from
- Ior
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)
- Inherited from
- Ior
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)
- Inherited from
- Ior
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)
- Inherited from
- Ior
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)
- Inherited from
- Ior
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)
- Inherited from
- Ior
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)
- Inherited from
- Ior
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)
- Inherited from
- Ior
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)
- Inherited from
- Ior
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)
- Inherited from
- Ior
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)
- Inherited from
- Ior
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))
- Inherited from
- Ior
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))
- Inherited from
- Ior
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
- Inherited from
- Ior