Combine with another Xor
value.
Combine with another Xor
value.
If this Xor
is a Left
then it will be returned as-is.
If this Xor
is a Right
and that
Xor
is a left, then that
will be
returned.
If both Xor
s are Right
s, then the Semigroup[BB]
instance will be used
to combine both values and return them as a Right
.
Note: If both Xor
s are Left
s then their values are not combined. Use
Validated
if you prefer to combine Left
values.
Examples:
scala> import cats.data.Xor scala> import cats.implicits._ scala> val l1: Xor[String, Int] = Xor.left("error 1") scala> val l2: Xor[String, Int] = Xor.left("error 2") scala> val r3: Xor[String, Int] = Xor.right(3) scala> val r4: Xor[String, Int] = Xor.right(4) scala> l1 combine l2 res0: Xor[String, Int] = Left(error 1) scala> l1 combine r3 res1: Xor[String, Int] = Left(error 1) scala> r3 combine l1 res2: Xor[String, Int] = Left(error 1) scala> r3 combine r4 res3: Xor[String, Int] = Right(7)
Returns a ValidatedNel representation of this disjunction with the Left
value
as a single element on the Invalid
side of the NonEmptyList.
Returns a ValidatedNel representation of this disjunction with the Left
value
as a single element on the Invalid
side of the NonEmptyList.