Skip to content

Order.fromComparable Method Signature Change to Allow java.sql.Date#4734

Merged
johnynek merged 4 commits into
typelevel:mainfrom
ikeyan:patch-1
Apr 10, 2025
Merged

Order.fromComparable Method Signature Change to Allow java.sql.Date#4734
johnynek merged 4 commits into
typelevel:mainfrom
ikeyan:patch-1

Conversation

@ikeyan
Copy link
Copy Markdown
Contributor

@ikeyan ikeyan commented Mar 29, 2025

The Order.fromComparable method signature in Order.scala has been modified to allow it to accept java.sql.Date.
This change enables the method to work with types such as java.sql.Date and other subtypes of java.util.Date which implements Comparable<java.util.Date>.

@satorg
Copy link
Copy Markdown
Contributor

satorg commented Apr 2, 2025

Hi @ikeyan , thank you for the PR, it can be helpful indeed!
I think it would be also nice if we could have a test that shows how the change works.

@ikeyan
Copy link
Copy Markdown
Contributor Author

ikeyan commented Apr 2, 2025

@satorg I added a test in OrderSuite.scala

Copy link
Copy Markdown
Contributor

@satorg satorg left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks!

def fromComparable[A <: Comparable[A]]: Order[A] = _ compareTo _
private type ContravariantComparable[A] = Comparable[? >: A]

def fromComparable[A <: ContravariantComparable[A]]: Order[A] = _ compareTo _
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

seems to me like this should be implicit potentially, perhaps at a lower priority.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@johnynek if an implicit parameter is added, would that break binary compatibility?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't mean an implicit parameter, I mean implicit def from comparable...

This won't break JVM binary compatibility. But maybe we need to lower the priority of this implicit by putting it in a trait and extending here.

@johnynek johnynek merged commit 324d528 into typelevel:main Apr 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants