Transforms an Either
into an EitherT
, lifted into the specified Applicative
.
Transforms an Either
into an EitherT
, lifted into the specified Applicative
.
Note: The return type is a FromEitherPartiallyApplied[F], which has an apply method on it, allowing you to call fromEither like this:
scala> import cats.implicits._ scala> val t: Either[String, Int] = Either.right(3) scala> EitherT.fromEither[Option](t) res0: EitherT[Option, String, Int] = EitherT(Some(Right(3)))
The reason for the indirection is to emulate currying type parameters.
Transforms an Option
into an EitherT
, lifted into the specified Applicative
and using
the second argument if the Option
is a None
.
Transforms an Option
into an EitherT
, lifted into the specified Applicative
and using
the second argument if the Option
is a None
.
scala> import cats.implicits._ scala> val o: Option[Int] = None scala> EitherT.fromOption[List](o, "Answer not known.") res0: EitherT[List, String, Int] = EitherT(List(Left(Answer not known.))) scala> EitherT.fromOption[List](Some(42), "Answer not known.") res1: EitherT[List, String, Int] = EitherT(List(Right(42)))
Alias for right
Alias for right
scala> import cats.data.EitherT scala> import cats.implicits._ scala> val o: Option[Int] = Some(3) scala> val n: Option[Int] = None scala> EitherT.liftT(o) res0: cats.data.EitherT[Option,Nothing,Int] = EitherT(Some(Right(3))) scala> EitherT.liftT(n) res1: cats.data.EitherT[Option,Nothing,Int] = EitherT(None)