-
-
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 Order instance for NonEmptySet (#2779) #2787
Conversation
@@ -417,3 +420,29 @@ sealed abstract private[data] class NonEmptySetInstances { | |||
def combine(x: NonEmptySet[A], y: NonEmptySet[A]): NonEmptySet[A] = x | y | |||
} | |||
} | |||
|
|||
sealed abstract private[data] class NonEmptySetInstances0 extends NonEmptySetInstances1 { | |||
implicit def catsDataOrderForNonEmptySetReal[A](implicit A: Order[A]): Order[NonEmptySet[A]] = |
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.
nit, is that Real
suffix still needed?
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.
Not sure. catsDataOrderForNonEmptySet is the name of the existing one (which I removed the implicit
keyword from). I can play around with it and see if it breaks bin compat
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.
did you mean private[data] def catsDataEqForNonEmptySet[A: Order]:
?
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.
yep since NonEmptySetInstances
extends NonEmptySetInstances0
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.
:) catsDataOrderForNonEmptySet
is different from catsDataEqForNonEmptySet
.
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.
🤦♂️ well if MiMa is happy then I'm happy :)
I'm gonna try remove the old catsDataEqForNonEmptySet
and see what happens
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.
sorry I wasn't clear. I meant that you didn't need to add a Real
suffix, because it didn't conflict with anything else. It's the right approach to remove the implict
keyword for catsDataEqForNonEmptySet
, but you didn't need to add private[data] since the class is already private[data]
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.
yes I got you. What I was also going to do is to remove the original catsDataEqForNonEmptySet
, since there's already a method named the same in NonEmptySetInstances1
. (I think JVM's use of invokevirtual call means it won't break bin compat - so it'll be both source and binary compatible)
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.
Done
@@ -19,6 +19,8 @@ package data | |||
|
|||
import cats.instances.sortedSet._ | |||
import cats.kernel._ | |||
import cats.syntax.order._ | |||
import cats.instances.sortedSet._ |
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.
duplicated from 3 lines above
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.
done
I would like to propose :
To make sure we indeed didn't break BC, we need to add a line calling the instance def here https://github.com/typelevel/cats/blob/master/binCompatTest/src/main/scala/catsBC/MimaExceptions.scala similar to the other tests there. |
Done (Sorry I was AFK for a week). Simplified the instances hierachy as suggested and added a different test class for testing binary package private instances. |
- Add Serializable tests for NonEmptySet instances
…mpatibility. Simplify NonEmptySet instances hierachy
CI is passing again @kailuowang 😄 |
SerializableTests.serializable(PartialOrder[NonEmptySet[ListWrapper[Int]]])) | ||
|
||
Eq[NonEmptySet[ListWrapper[Int]]] | ||
PartialOrder[NonEmptySet[ListWrapper[Int]]] |
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.
These two lines are unnecessary, no?
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.
These instance tests are written based on https://github.com/typelevel/cats/blob/4f92efedd2c30534c07b5f75a72b22e3e1ba9b13/tests/src/test/scala/cats/tests/NonEmptyListSuite.scala and from what I can gather is that it's to test that an Eq
and PartialOrder
instance can be resolved when an Order
instance is in scope.
Do you think they are redundant?
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.
The resolution is already tested in the law and serialization tests
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.
ok
// NOTE: Order[NonEmptySet[A]] instance depends on Order[SortedSet[A]]. SortedSet only has Order instance which depends on Order[A] instance | ||
// and thus the only way we can get PartialOrder[NonEmptySet[A]] is via construction of Order[NonEmptySet[A]] | ||
checkAll("NonEmptySet[ListWrapper[Int]]", PartialOrderTests[NonEmptySet[ListWrapper[Int]]].partialOrder) | ||
checkAll("PartialOrder[NonEmptySet[ListWrapper[Int]]]", |
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 I am missing something here, but this is covered by the Order
test above, since we don't have a different way to construct a PartialOrder
, not sure if we need this test?
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.
you're right. Removed thx
package cats.data | ||
import cats.implicits._ | ||
|
||
object CatsDataPackagePrivateMimaExceptions { |
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.
My bad. I should've checked that mima no longer falsely claims that this type of change breaks BC. So this is no longer needed? Would you mine removing it?
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.
done
Thank you for contributing to Cats!
This is a kind reminder to run
sbt prePR
and commit the changed files, if any, before submitting.