Combine with another Either
value.
Combine with another Either
value.
If this Either
is a Left
then it will be returned as-is.
If this Either
is a Right
and that
Either
is a left, then that
will be
returned.
If both Either
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 Either
s are Left
s then their values are not combined. Use
Validated
if you prefer to combine Left
values.
Examples:
scala> import cats.implicits._ scala> val l1: Either[String, Int] = Either.left("error 1") scala> val l2: Either[String, Int] = Either.left("error 2") scala> val r3: Either[String, Int] = Either.right(3) scala> val r4: Either[String, Int] = Either.right(4) scala> l1 combine l2 res0: Either[String, Int] = Left(error 1) scala> l1 combine r3 res1: Either[String, Int] = Left(error 1) scala> r3 combine l1 res2: Either[String, Int] = Left(error 1) scala> r3 combine r4 res3: Either[String, Int] = Right(7)
lift the Either
into a F[_]
with ApplicativeError[F, A]
instance
lift the Either
into a F[_]
with ApplicativeError[F, A]
instance
scala> import cats.implicits._ scala> import cats.data.EitherT scala> val e: Either[String, Int] = Right(3) scala> e.liftTo[EitherT[Option, CharSequence, ?]] res0: cats.data.EitherT[Option, CharSequence, Int] = EitherT(Some(Right(3)))
Transform the Either
into a cats.data.EitherT while lifting it into the specified Applicative.
Transform the Either
into a cats.data.EitherT while lifting it into the specified Applicative.
scala> import cats.implicits._ scala> val e: Either[String, Int] = Right(3) scala> e.toEitherT[Option] res0: cats.data.EitherT[Option, String, Int] = EitherT(Some(Right(3)))
Returns a cats.data.ValidatedNel representation of this disjunction with the Left
value
as a single element on the Invalid
side of the cats.data.NonEmptyList.