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

Don't require Order for the value on Cogen for SortedMap and NonEmptyMap #4296

Merged
merged 3 commits into from
Oct 10, 2022

Conversation

cquiroz
Copy link
Contributor

@cquiroz cquiroz commented Sep 11, 2022

It seems we don't need to require an Order instance for Cogen of SortedMap and NonEmptyMap. We only need it for the keys

Fixes #4295

Comment on lines 133 to 134
implicit def cogenNonEmptyMap[K: Order: Cogen, A: Order: Cogen]: Cogen[NonEmptyMap[K, A]] =
implicit def cogenNonEmptyMap[K: Order: Cogen, A: Cogen]: Cogen[NonEmptyMap[K, A]] =
Cogen[SortedMap[K, A]].contramap(_.toSortedMap)
Copy link
Member

Choose a reason for hiding this comment

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

For binary compatibility we have to keep the old signature as well, like this:

@deprecated("Preserved for bincompat", "2.9.0")
def cogenNonEmptyMap[K, A](kOrder: Order[K], kCogen: Cogen[K], aOrder: Order[A], aCogen: Coge[A]): Cogen[NonEmptyMap[K, A]]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean copy the old signature and make it non implicit?

Copy link
Member

Choose a reason for hiding this comment

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

yes, exactly.

@armanbilge armanbilge changed the title Don't require Order for the value on Cogen for SortedMap and NonEmptyMap Don't require Order for the value on Cogen for SortedMap and NonEmptyMap Sep 11, 2022
@armanbilge armanbilge added this to the 2.9.0 milestone Sep 11, 2022
@armanbilge armanbilge added the bug label Sep 11, 2022
@cquiroz
Copy link
Contributor Author

cquiroz commented Sep 11, 2022

Added delegation as requested

Copy link
Member

@armanbilge armanbilge 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, thanks!

cogenNonEmptyMap[K, A]
}

implicit def cogenNonEmptyMap[K: Order: Cogen, A: Cogen]: Cogen[NonEmptyMap[K, A]] =
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm confused why we even need the K: Order here. A SortedMap knows the Ordering[K].

Doesn't this also work only with K: Cogen, A: Cogen?

Copy link
Member

@armanbilge armanbilge Sep 12, 2022

Choose a reason for hiding this comment

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

I was confused about this as well :) Scalacheck implements the Cogen[Map] by transforming it to an ordered collection.

https://github.com/typelevel/scalacheck/blob/7bb1a47af2313f7e7935d34cce255f7b7c0b1b31/core/shared/src/main/scala/org/scalacheck/Cogen.scala#L129-L130

Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch! As a side note: in fact, there are quite a lot of places in the Cats codebase where a constraint is demanded but not actually used. So this is why I think it would be great to have "unused" warnings enforced eventually.

@satorg satorg self-requested a review September 15, 2022 15:19
@armanbilge
Copy link
Member

@satorg did you want to re-review this?

@satorg
Copy link
Contributor

satorg commented Oct 10, 2022

Oh, I thought that Oscar asked a question and we're awaiting an answer from @cquiroz ...
But now I've realized that the concern had been cleared, hadn't it?

@armanbilge
Copy link
Member

Yes, I think this one is ready for merge :)

@armanbilge armanbilge merged commit 3ffee33 into typelevel:main Oct 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unnecessary Order param for SortedMap/NonEmptyMap Cogen
4 participants