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

Put liftT on the companion object of XorT #1215

Merged
merged 5 commits 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/XorT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,21 @@ trait XorTFunctions {

final def pure[F[_], A, B](b: B)(implicit F: Applicative[F]): XorT[F, A, B] = right(F.pure(b))

/**
* Alias for [[XorT.right]]
* {{{
* scala> import cats.data.XorT
* scala> import cats.implicits._
* scala> val o: Option[Int] = Some(3)
* scala> val n: Option[Int] = None
* scala> XorT.liftT(o)
* res0: cats.data.XorT[Option,Nothing,Int] = XorT(Some(Right(3)))
* scala> XorT.liftT(n)
* res1: cats.data.XorT[Option,Nothing,Int] = XorT(None)
* }}}
*/
final def liftT[F[_], A, B](fb: F[B])(implicit F: Functor[F]): XorT[F, A, B] = right(fb)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we even need Functor here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the implicit evidence for a Functor it won't compile since right needs one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. I made the mistake of believing that was just Xor.right Sorry for the noise.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good, I'm just happy I could answer :)


/** Transforms an `Xor` into an `XorT`, lifted into the specified `Applicative`.
*
* Note: The return type is a FromXorPartiallyApplied[F], which has an apply method
Expand Down Expand Up @@ -280,7 +295,7 @@ private[data] abstract class XorTInstances extends XorTInstances1 {
type TC[M[_]] = Functor[M]

def liftT[M[_]: Functor, A](ma: M[A]): XorT[M, E, A] =
XorT(Functor[M].map(ma)(Xor.right))
XorT.liftT(ma)
}

implicit def catsMonoidForXorT[F[_], L, A](implicit F: Monoid[F[L Xor A]]): Monoid[XorT[F, L, A]] =
Expand Down