Skip to content

Commit

Permalink
Add Coproduct fold (fixes #987)
Browse files Browse the repository at this point in the history
  • Loading branch information
peterneyens committed May 14, 2016
1 parent 3febb06 commit 74754ed
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion core/src/main/scala/cats/data/Coproduct.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cats
package data

import cats.arrow.NaturalTransformation
import cats.functor.Contravariant

/** `F` on the left and `G` on the right of [[Xor]].
Expand Down Expand Up @@ -57,6 +58,8 @@ final case class Coproduct[F[_], G[_], A](run: F[A] Xor G[A]) {
def toValidated: Validated[F[A], G[A]] =
run.toValidated

def fold[H[_]](f: NaturalTransformation[F, H], g: NaturalTransformation[G, H]): H[A] =
run.fold(f.apply, g.apply)
}

object Coproduct extends CoproductInstances {
Expand All @@ -78,7 +81,6 @@ object Coproduct extends CoproductInstances {
def left[G[_]]: CoproductLeft[G] = new CoproductLeft[G]

def right[F[_]]: CoproductRight[F] = new CoproductRight[F]

}

private[data] sealed abstract class CoproductInstances3 {
Expand Down

0 comments on commit 74754ed

Please sign in to comment.