-
-
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
cats.Order: Support for pattern matching on comparison results #1101
Comments
Note that you can still get quite the same syntax without changing object GreaterThan {
def unapply(i: Int): Boolean = i > 0
} (a comparison b) match {
case GreaterThan() => ???
} |
@julienrf I thought the same thing at first. The problem is that while you do get the syntax, you don't get the exhaustive matching. So if you match on the |
Fair point :) |
IMO this isnt quite done, since there's no syntax to enable I think (?) Ive seen some syntax in the cats project autogenerated, maybe from |
@benhutchison Ah true, oops forgot about that. I believe kernel doesn't use simulacrum to minimize dependencies |
When doing comparisons with cats.Order, would be desirable to pattern match on the cases, like eg:
Order.compare returns an Int for performance and Java 1.7 compat reasons, which is fair enough, when you need that. But that requires an if (c <0) ... else if (c == 0) .. else ... construct to handle a comparison; less readable than the above alternative IMO.
Proposal is a function, implemented on top of
compare: Int
, perhaps namedcomparison: Comparison
that returned a case object (GreaterThan etc) for pleasant pattern matching.Gitter discussion: https://gitter.im/typelevel/cats?at=5758beb8064b9e7266f0c086
The text was updated successfully, but these errors were encountered: