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->Ordering implicit conversion to implicits, instances #1670

Merged

Conversation

edmundnoble
Copy link
Contributor

Does... anyone know where I would put a test? If it's worth testing? Also, kernel is open for changes for 1.0, right?

object Order extends OrderFunctions[Order] {
trait OrderToOrderingConversion {
/**
* Implicitly convert a `Order[A]` to a `scala.math.Ordering[A]`
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not an implicit conversion which is something else. Can we say something like "provide an Ordering instance equivalent to the Order".

It does convert, and so I know I'm being pedantic, but I really don't like implicit conversions except for method enrichment, and in any case an implicit conversion has exactly one non-implicit parameter.

Copy link
Contributor Author

@edmundnoble edmundnoble May 14, 2017

Choose a reason for hiding this comment

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

I agree, but I changed this comment already. I am not seeing how it showed up here 😛

Copy link
Contributor Author

@edmundnoble edmundnoble May 14, 2017

Choose a reason for hiding this comment

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

Ah sorry. Forgot to push. Is the edited one alright?

ev.toOrdering
}

object Order extends OrderFunctions[Order] with OrderToOrderingConversion {
Copy link
Contributor

Choose a reason for hiding this comment

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

I haven't researched this, but I am wondering if we place the method directly in the object instead of a trait, will that help binary comp going forward (on scala 2.11.x)?

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any benefit to having implicit final def catsKernelOrderingForOrder[A](implicit ev: Order[A]): Ordering[A] inside the Order companion object? I don't think that scala will look here when it is searching for an Ordering instance. I could see a minor benefit of having a non-implicit version of this method inside the companion object. As it stands it seems like it's just a liability as I would expect you to get ambiguous implicits if you've imported both cats.implicits._ and cats.kernel.Order._.

Copy link
Contributor

Choose a reason for hiding this comment

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

Now I don't know why I thought that would be a valid point to make. It has to be a trait for cats.implicits._. Sorry about the noise.

@johnynek
Copy link
Contributor

for those following at home, the mima check failed on kernel.

@edmundnoble
Copy link
Contributor Author

I know that this isn't binary compatible. Is code duplication an acceptable fix?

@johnynek
Copy link
Contributor

@edmundnoble code duplication is an acceptable fix (i.e. they don't need to share the trait).

@codecov-io
Copy link

codecov-io commented Jun 28, 2017

Codecov Report

Merging #1670 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1670      +/-   ##
==========================================
+ Coverage   94.17%   94.17%   +<.01%     
==========================================
  Files         256      256              
  Lines        4207     4208       +1     
  Branches       93       93              
==========================================
+ Hits         3962     3963       +1     
  Misses        245      245
Impacted Files Coverage Δ
core/src/main/scala/cats/instances/order.scala 100% <ø> (ø) ⬆️
kernel/src/main/scala/cats/kernel/Order.scala 89.18% <100%> (+0.3%) ⬆️

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 99b543b...5179bb3. Read the comment docs.

@edmundnoble
Copy link
Contributor Author

Binary compatible, now.

@johnynek
Copy link
Contributor

I wonder if this is going to create ambiguous implicits.

Can we have a test where we do import cats.implicits._ in a scope and make sure that we can still do implicitly[Ordering[String]] etc... for some types that already have scala Orderings?

@edmundnoble
Copy link
Contributor Author

Ambiguity test added; it passes, I'm fairly sure the reason is that the Ordering companion object is firmly below imports in implicit scope.

@edmundnoble
Copy link
Contributor Author

@johnynek Any more feedback? Just rebased on master and squashed.

@johnynek
Copy link
Contributor

johnynek commented Jul 5, 2017

👍

@edmundnoble edmundnoble merged commit 73d180b into typelevel:master Jul 6, 2017
@edmundnoble
Copy link
Contributor Author

Merged with two sign-offs.

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.

6 participants