diff --git a/core/src/main/scala/cats/data/Coproduct.scala b/core/src/main/scala/cats/data/Coproduct.scala index e2b4a55ca86..d82f9608a8a 100644 --- a/core/src/main/scala/cats/data/Coproduct.scala +++ b/core/src/main/scala/cats/data/Coproduct.scala @@ -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]]. @@ -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 { @@ -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 {