Open mkotsbak opened 8 years ago
With -Ypartial-unification
this works:
import cats.data.{Nested, Validated}
import cats.implicits._
val a = Nested(1.validNel[String].some)
val b = Nested(2.validNel[String].some)
val c = Nested("boom1".invalidNel[Int].some)
val d = Nested("boom2".invalidNel[Int].some)
(a |@| b).map(_ + _)
// Nested[Option,[+A]ValidatedNel[String,A],Int] =
// Nested(Some(Valid(3)))
(a |@| c).map(_ + _)
// Nested[Option,[+A]ValidatedNel[String,A],Int] =
// Nested(Some(Invalid(NonEmptyList(boom1))))
(c |@| d).map(_ + _)
// Nested[Option,[+A]ValidatedNel[String,A],Int] =
// Nested(Some(Invalid(NonEmptyList(boom1, boom2))))
(c, d).map2(_ + _) // mapN after PR #1487
// Nested[Option,[+A]ValidatedNel[String,A],Int] =
// Nested(Some(Invalid(NonEmptyList(boom1, boom2))))
Note that the cartesian builder syntax will (probably) be replaced by enriched tuple methods.
Nested[_, _, _] |@| Nested[_, _, _]
should probably result in a nested cartesian builder, so that it is easier to handleNested[_, Validated, _]