-
-
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
Don't combine lefts on Xor and XorT combine #1034
Conversation
Resolves typelevel#888 I don't think there's really a _right_ answer here. Both methods of combining `Xor`s are straightforward and law-abiding. However, I think that since in pretty much every other context (including the `SemigroupK` instances), `Xor` does not combine failures and `Validated` does, it is less surprising behavior to not combine left values in `combine` methods for `Xor` and `XorT`. Some notes about related implementations: - Scalaz's respective methods (and semigroup instances) _do_ combine errors, so this is a deviation from that. - The `Semigroup` for `Either` in Haskell has doesn't combine values at all, but returns the first `Right` (if any), making it equivalent to the behavior of `orElse` and the `SemigroupK` instance for `Xor`. Since we have already decided to not go with `orElse`-like behavior for our `Option` semigroup, I'm inclined to not take this approach for `Xor`. See also typelevel#996 (comment)
case Xor.Right(b1) => that match { | ||
case Xor.Left(a2) => Xor.Left(a2) | ||
case l @ Xor.Left(_) => l |
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.
Tiny thing, but let's call this left
instead of l
-- I think it reads a lot better.
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.
👍 updated
Tiny style comment, but 👍 from me! |
👍 . This makes for {
x <- this
y <- that
} yield SemigroupInstance.combine(x,y) which make sense as you mostly want to use |
Per @non's suggestion.
Current coverage is 88.84%
@@ master #1034 diff @@
==========================================
Files 215 215
Lines 2726 2724 -2
Methods 2664 2663 -1
Messages 0 0
Branches 57 57
==========================================
Hits 2420 2420
+ Misses 306 304 -2
Partials 0 0
|
👍 |
Resolves #888
I don't think there's really a right answer here. Both methods of
combining
Xor
s are straightforward and law-abiding. However, I thinkthat since in pretty much every other context (including the
SemigroupK
instances),Xor
does not combine failures andValidated
does, it is less surprising behavior to not combine left values in
combine
methods forXor
andXorT
.Some notes about related implementations:
errors, so this is a deviation from that.
Semigroup
forEither
in Haskell has doesn't combine values atall, but returns the first
Right
(if any), making it equivalent tothe behavior of
orElse
and theSemigroupK
instance forXor
.Since we have already decided to not go with
orElse
-like behaviorfor our
Option
semigroup, I'm inclined to not take this approach forXor
.See also
#996 (comment)
cc @notxcain @aaronlevin @travisbrown @tpolecat @stew whom I think have all weighed in on this or similar items in the past