Fold this coproduct into a new type constructor using two natural transformations.
Fold this coproduct into a new type constructor using two natural transformations.
Example:
scala> import cats.arrow.NaturalTransformation scala> import cats.data.Coproduct scala> val listToOption = | new NaturalTransformation[List, Option] { | def apply[A](fa: List[A]): Option[A] = fa.headOption | } scala> val optionToOption = NaturalTransformation.id[Option] scala> val cp1: Coproduct[List, Option, Int] = Coproduct.leftc(List(1,2,3)) scala> val cp2: Coproduct[List, Option, Int] = Coproduct.rightc(Some(4)) scala> cp1.fold(listToOption, optionToOption) res0: Option[Int] = Some(1) scala> cp2.fold(listToOption, optionToOption) res1: Option[Int] = Some(4)
The underlying Xor.
F
on the left andG
on the right of Xor.The underlying Xor.