Skip to content

Commit

Permalink
Merge pull request #1301 from adelbertc/eithert-catchup
Browse files Browse the repository at this point in the history
Port #1215 to EitherT
  • Loading branch information
kailuowang committed Aug 20, 2016
2 parents ae69eaf + d6841a5 commit 6e12494
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion core/src/main/scala/cats/data/EitherT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]] =
Expand Down

0 comments on commit 6e12494

Please sign in to comment.