Skip to content
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

Merged
merged 5 commits into from
Jun 11, 2019
Merged

Add Order instance for NonEmptySet (#2779) #2787

merged 5 commits into from
Jun 11, 2019

Conversation

jatcwang
Copy link
Contributor

  • Add Serializable tests for NonEmptySet instances

Thank you for contributing to Cats!

This is a kind reminder to run sbt prePR and commit the changed files, if any, before submitting.

@codecov-io
Copy link

codecov-io commented Apr 12, 2019

Codecov Report

Merging #2787 into master will decrease coverage by 0.01%.
The diff coverage is 66.66%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #2787      +/-   ##
=========================================
- Coverage   94.21%   94.2%   -0.02%     
=========================================
  Files         368     368              
  Lines        6948    6949       +1     
  Branches      303     303              
=========================================
  Hits         6546    6546              
- Misses        402     403       +1
Impacted Files Coverage Δ
core/src/main/scala/cats/data/NonEmptySet.scala 97.59% <66.66%> (-1.2%) ⬇️
laws/src/main/scala/cats/laws/discipline/Eq.scala 33.33% <0%> (ø) ⬆️
...in/scala/cats/kernel/instances/short/package.scala
...ain/scala/cats/kernel/instances/unit/package.scala
...ain/scala/cats/kernel/instances/uuid/package.scala
...n/scala/cats/kernel/instances/bitSet/package.scala
...main/scala/cats/kernel/instances/set/package.scala
...in/scala/cats/kernel/instances/queue/package.scala
...main/scala/cats/kernel/instances/map/package.scala
...scala/cats/kernel/instances/duration/package.scala
... and 44 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b504edc...de79fe2. Read the comment docs.

@kailuowang kailuowang self-requested a review April 17, 2019 01:52
@@ -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]] =
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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]: ?

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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]

Copy link
Contributor Author

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)

Copy link
Contributor Author

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._
Copy link
Contributor

@kailuowang kailuowang Apr 17, 2019

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@kailuowang
Copy link
Contributor

kailuowang commented Apr 17, 2019

I would like to propose :
We don't need two new classes, just one NonEmptySetInstances0 is enough, you can place the eq instance there and the order instance in NonEmptySetInstances
I think this change is BC but Mima will raise a false alarm. We need to add a mima exception
here https://github.com/typelevel/cats/blob/master/build.sbt#L288

ProblemFilters.exclude[IncompatibleMethTypeProblem]("cats.data.NonEmptySetInstances.catsDataEqForNonEmptySet")

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.

@jatcwang
Copy link
Contributor Author

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.

@jatcwang
Copy link
Contributor Author

CI is passing again @kailuowang 😄

SerializableTests.serializable(PartialOrder[NonEmptySet[ListWrapper[Int]]]))

Eq[NonEmptySet[ListWrapper[Int]]]
PartialOrder[NonEmptySet[ListWrapper[Int]]]
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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

Copy link
Contributor Author

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]]]",
Copy link
Contributor

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?

Copy link
Contributor Author

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 {
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@kailuowang kailuowang merged commit 71bbf39 into typelevel:master Jun 11, 2019
@kailuowang kailuowang added this to the 2.0.0-RC1 milestone Aug 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants