-
-
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
Add or combinator to Validated #1448
Conversation
A related discussion is happening in #1447 |
Current coverage is 92.20% (diff: 100%)@@ master #1448 diff @@
==========================================
Files 242 242
Lines 3618 3619 +1
Methods 3550 3549 -1
Messages 0 0
Branches 68 70 +2
==========================================
+ Hits 3336 3337 +1
Misses 282 282
Partials 0 0
|
Ah I see, should I close this PR then, or wait for a decision from that discussion and modify the PR accordingly? |
Your PR, your call. I just wanted to connect this PR and you to that discussion, in case you might want to take part in. |
835b2ef
to
3cd942c
Compare
I'd rather this be the default behavior, but if others really think that will cause hard bugs I'm okay with One issue: can we comment on each linking to the other? In the comment on orElse contrast it with or and likewise for the opposite? |
3cd942c
to
ccc3877
Compare
Yup, I added that. |
I'd also vote for accumulating |
Maybe |
ccc3877
to
b91aa21
Compare
I think that's probably the right call, I've changed the code to reflect that. |
👍 |
How about adding some tests? |
@@ -44,14 +44,27 @@ sealed abstract class Validated[+E, +A] extends Product with Serializable { | |||
|
|||
/** | |||
* Return this if it is Valid, or else fall back to the given default. | |||
* The functionality is similar to that of [[orElse]] except for failure accumulation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe specifically mention that if both instances are failed, only the error on the right is preserved? I think the current sentence is good, but the behavior should also be explicitly explained as well.
b91aa21
to
af6c103
Compare
Added a couple tests and cleaned up the doc on |
👍 but I'd vote to hold off on merging this until 0.8.1 is published so that we can keep things simple by publishing off of master. (Even though this would be binary compatible it's a big enough change in behavior that I don't think it should happen in a patch release.) |
+1 to not changing in a patch release. That said, I do want to point out something here: if the So, if you wanted to count failures, you would use Something in the back of my mind makes me think What we are talking about here is like I know, I pushed strongly for this earlier, and the motivation there was consistency: always use the semigroup when you can. However, the error counting example seems to give me a bit of pause. Maybe |
@johnynek For me both the consistency and the expectation that Even in the case of error counting, I think the accumulating behavior at least arguably makes sense. You actually did try both sides (which may have included attempting to decode something, etc.), and if I'm using (Also I was wrong about this being binary compatible in my previous comment, since there's the new |
@travisbrown good point. Consistency is a strong argument. +1. |
Hmm, I just ran into a fact that's making me question my original position (in favor of accumulating In circe decoders can be run in either fail-fast or error-accumulating mode, and there's a requirement that simply dropping all errors except the first in error-accumulating mode should always give the same result as fail-fast mode. This holds for all decoders defined in the library except for ones built with I'm not sure this is much of an argument one way or the other, but it does feel a little suspicious. |
I'm actually not sure class List[T] {
def orElse[U >: T](that: List[U]): List[U] =
if (nonEmpty) this
else that
} we would not want consistency with |
Is there a stronger consensus here? I can change what I've got if the opinion is that the |
@mgzuber At this point I don't feel strongly either way—I'm no longer convinced that either implementation is more consistent or elegant, so as long as they're both available I don't think the names matter all that much. |
a very clear approach would be to add or something like that. The name should make it clear that at least this one gives both invalids. |
@johnynek that would be in tune with the scalaz approach (the method name is That being said, something like |
So, in the absence of a strong argument one way or the other, I think the fallback of API stability may win the day in my book. So, I would say +1 to |
af6c103
to
56aa6d2
Compare
Done |
56aa6d2
to
3102154
Compare
👍 Thanks very much! |
👍 |
No description provided.