Skip to content

Commit

Permalink
Merge pull request #1100 from peterneyens/simplify-to-constraint
Browse files Browse the repository at this point in the history
Simplify the constraint on Xor/XorT/Ior to[] by using Alternative
  • Loading branch information
adelbertc committed Jun 9, 2016
2 parents 3e56801 + adbaa22 commit 88cbe95
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/data/Ior.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ sealed abstract class Ior[+A, +B] extends Product with Serializable {
final def toOption: Option[B] = right
final def toList: List[B] = right.toList

final def to[F[_], BB >: B](implicit monoidKF: MonoidK[F], applicativeF: Applicative[F]): F[BB] =
fold(_ => monoidKF.empty, applicativeF.pure, (_, b) => applicativeF.pure(b))
final def to[F[_], BB >: B](implicit F: Alternative[F]): F[BB] =
fold(_ => F.empty, F.pure, (_, b) => F.pure(b))

final def swap: B Ior A = fold(Ior.right, Ior.left, (a, b) => Ior.both(b, a))

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/data/Xor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ sealed abstract class Xor[+A, +B] extends Product with Serializable {
def withValidated[AA,BB](f: Validated[A,B] => Validated[AA,BB]): AA Xor BB =
f(toValidated).toXor

def to[F[_], BB >: B](implicit monoidKF: MonoidK[F], applicativeF: Applicative[F]): F[BB] =
fold(_ => monoidKF.empty, applicativeF.pure)
def to[F[_], BB >: B](implicit F: Alternative[F]): F[BB] =
fold(_ => F.empty, F.pure)

def bimap[C, D](fa: A => C, fb: B => D): C Xor D = this match {
case Xor.Left(a) => Xor.Left(fa(a))
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/data/XorT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ final case class XorT[F[_], A, B](value: F[A Xor B]) {

def toOption(implicit F: Functor[F]): OptionT[F, B] = OptionT(F.map(value)(_.toOption))

def to[G[_]](implicit functorF: Functor[F], monoidKG: MonoidK[G], applicativeG: Applicative[G]): F[G[B]] =
functorF.map(value)(_.to[G, B])
def to[G[_]](implicit F: Functor[F], G: Alternative[G]): F[G[B]] =
F.map(value)(_.to[G, B])

def collectRight(implicit F: MonadCombine[F]): F[B] =
F.flatMap(value)(_.to[F, B])
Expand Down

0 comments on commit 88cbe95

Please sign in to comment.