Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port #1215 to EitherT #1301

Merged
merged 1 commit into from
Aug 20, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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