-
-
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
Monoid[Comparison] - lexographical ordering #2087
Conversation
Binary compat check failed, I assume because I renamed the instance. Should I add it under a separate member or do we want to let this one slide in? |
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.
LGTM, thanks! :)
Is there anything in particular that motivates this On a tangential note something that seems a little more straightforward to me would be strengthening from |
@ceedubs It implements something analogous to lexographical ordering - if you want to compare two Most recently I used this here (which is what prompted this PR), and I've used the instance in Scalaz several times in the past when I want behavior described above. As a fun fact, def whenEqual(o: Order[A]): Order[A]
|
Thanks @adelbertc I can see why you would want that. I apologize in advance, but I'm going to take this down a bit of a rabbit hole. I've done this sort of thing with scalaz a lot where I do something like: implicit val posOrder: Order[Pos] =
Order.by(_.fileName) |+| Order.by(_.line) |+| Order.by(_.column) I added a To me something about the Furthermore, I think that chaining together Sorry for the wall of text. I just kind of feel like this might mostly be useful as a workaround for something that should probably be easier anyway, and it seemed a little inconsistent to add this. I'm definitely curious to hear people`s thoughts. |
One important difference between doing this through final case class Foo(
a: Int,
b: String,
c: Double,
d: List[Int]
/* ... *./
) and in different contexts only want to compare between |
@adelbertc you raise some good points. Personally I've kind of settled on a middle-ground when it comes to type class coherence. I'm fine with there being multiple 👍 I'm good with the |
I ran into similar while upgrading from cats-0.9 last night. I settled on: Order.whenEqualMonoid.combineAll(List(
Order.by(_.vertex),
Order.by(_.label),
Order.by(_.inAdj.sorted),
Order.by(_.outAdj.sorted))) I like this a little better than the |
@rossabaker Thanks for weighing in. That looks like a pretty clean solution. I may separately pursue an agenda of an implicit |
Does having one preclude having the other? Are there other more appropriate instances of a |
No, I definitely don't think so.
I doubt it. It seems unlikely to me that someone would reach for one outside of the use-case that you described. |
I think for this PR 2 questions remain:
|
ah, I thought it was just me finding Order a bit cumbersome :) |
Once we get typelevel/cats#2087, we can revert to the way things were.
This has been sitting around for a while, but FWIW I vote for adding this and for the time being maintaining the current name to preserve binary compatibility (but we may want to change the name for Cats 3.0). |
No description provided.