Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cartesian operations on Nested #1343

Open
mkotsbak opened this issue Sep 1, 2016 · 1 comment
Open

Add cartesian operations on Nested #1343

mkotsbak opened this issue Sep 1, 2016 · 1 comment

Comments

@mkotsbak
Copy link
Contributor

mkotsbak commented Sep 1, 2016

Nested[_, _, _] |@| Nested[_, _, _] should probably result in a nested cartesian builder, so that it is easier to handle Nested[_, Validated, _]

@peterneyens
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants