From 0a155bb0afa06c6209215d47c0a9edd7131a965f Mon Sep 17 00:00:00 2001 From: Adelbert Chang Date: Fri, 19 Aug 2016 20:07:40 -0700 Subject: [PATCH] Port #1215 to EitherT --- core/src/main/scala/cats/data/EitherT.scala | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/core/src/main/scala/cats/data/EitherT.scala b/core/src/main/scala/cats/data/EitherT.scala index 66915a74042..31d7245dfc8 100644 --- a/core/src/main/scala/cats/data/EitherT.scala +++ b/core/src/main/scala/cats/data/EitherT.scala @@ -218,6 +218,21 @@ trait EitherTFunctions { final def pure[F[_], A, B](b: B)(implicit F: Applicative[F]): EitherT[F, A, B] = right(F.pure(b)) + /** + * 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) + * }}} + */ + final def liftT[F[_], A, B](fb: F[B])(implicit F: Functor[F]): EitherT[F, A, B] = right(fb) + /** Transforms an `Either` into an `EitherT`, lifted into the specified `Applicative`. * * Note: The return type is a FromEitherPartiallyApplied[F], which has an apply method @@ -272,7 +287,7 @@ private[data] abstract class EitherTInstances extends EitherTInstances1 { type TC[M[_]] = Functor[M] def liftT[M[_]: Functor, A](ma: M[A]): EitherT[M, E, A] = - EitherT(Functor[M].map(ma)(Either.right)) + EitherT.liftT(ma) } implicit def catsMonoidForEitherT[F[_], L, A](implicit F: Monoid[F[Either[L, A]]]): Monoid[EitherT[F, L, A]] =