-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Validate.orElse behavior #1447
Comments
I support the I guess |
Well, I would say that the I think it is strange that in the Like, if you want the |
So I have no idea what people in the world want. I can imagine situations where you do want this kind of monadic behavior (first check A, if it's fine you're done, otherwise check B ignoring A's failure). But you're right that there needs to be a way to do the applicatively that is at least as ergonomic. I would be fine changing |
@johnynek Isn't your scala> import cats.data.{ Validated, ValidatedNel }
import cats.data.{Validated, ValidatedNel}
scala> import cats.syntax.semigroupk._
import cats.syntax.semigroupk._
scala> val bad1: ValidatedNel[String, Int] = Validated.invalidNel("foo")
bad1: cats.data.ValidatedNel[String,Int] = Invalid(NonEmptyList(foo))
scala> val bad2: ValidatedNel[String, Int] = Validated.invalidNel("bar")
bad2: cats.data.ValidatedNel[String,Int] = Invalid(NonEmptyList(bar))
scala> val good1: ValidatedNel[String, Int] = Validated.valid(1)
good1: cats.data.ValidatedNel[String,Int] = Valid(1)
scala> val good2: ValidatedNel[String, Int] = Validated.valid(2)
good2: cats.data.ValidatedNel[String,Int] = Valid(2)
scala> good1 <+> good2
res0: cats.data.Validated[cats.data.NonEmptyList[String],Int] = Valid(1)
scala> bad1 <+> good1
res1: cats.data.Validated[cats.data.NonEmptyList[String],Int] = Valid(1)
scala> bad1 <+> bad2
res2: cats.data.Validated[cats.data.NonEmptyList[String],Int] = Invalid(NonEmptyList(foo, bar)) I'm a little surprised by the current |
@travisbrown They are similar, although |
It's always a bummer when we have two functions of the same type signature that are slightly different. I hope no one finds a compelling reason we would not want to use the Semigroup in orElse since it would be nicer to have fewer things to consider. |
If we were creating this from scratch I agree with you 100%. I want to try to figure out to what degree people are relying on (or need) the current behavior before committing to changing it (or doing something else). |
Looks like it's been this way since the beginning: https://github.com/typelevel/cats/pull/239/files#diff-729adf389426da6b093a5283e0e2edaeR51 @stew Do you feel strongly that the definition should stay the same? |
I put in PR #1448 before seeing this issue/discussion thread, so I figure I'll add my two cents as someone who is trying to migrate code depending on scalaz to cats. I can only imagine that the current definition of It seems to me that the decision is leaning towards adding an |
Also added orThen combinator to preserve old functionality. Closes typelevel#1447
Also added orThen combinator to preserve old functionality. Closes typelevel#1447
Also added orThen combinator to preserve old functionality. Closes typelevel#1447
If we look at validated orElse:
https://github.com/typelevel/cats/blob/master/core/src/main/scala/cats/data/Validated.scala#L51
Unlike other uses of Validated, if both are Invalid, we only get the right here. It would be nice to have a combinator like:
In fact, I would have thought that is what
orElse
does. It is a bummer to lose the left error in this case when both have errored.The text was updated successfully, but these errors were encountered: