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 Foldable#[max|min]ByOption, Reducible#[maxBy|minBy] #2385

Closed
kubukoz opened this issue Aug 12, 2018 · 6 comments · Fixed by #3084
Closed

Add Foldable#[max|min]ByOption, Reducible#[maxBy|minBy] #2385

kubukoz opened this issue Aug 12, 2018 · 6 comments · Fixed by #3084

Comments

@kubukoz
Copy link
Member

kubukoz commented Aug 12, 2018

No description provided.

@leusgalvan
Copy link
Contributor

Can I take this?

@LukaJCB
Copy link
Member

LukaJCB commented Aug 23, 2018

@leusgalvan go right ahead!
You'll have to add these to a separate syntax trait, due to bin compatibility, just a heads up :)
Feel free to ask questions, about that!

@leusgalvan
Copy link
Contributor

@LukaJCB sorry for the delay. Would love to know a little bit more about how bin compatibility is managed in Cats, is there any source you can point me to? In particular I'd like to know the relationship between the *Syntax, *Ops and *Compat classes.

From what I've read in the contributing guide I can use mimaReportBinaryIssues to detect the issues.

Thanks in advance!

@LukaJCB
Copy link
Member

LukaJCB commented Aug 28, 2018

The *Ops classes are classes that add direct syntax to certain type classes.
A *Syntax class has several implicit conversions from a type to their corresponding *Ops class, to provide the given syntax.
*Compat classes are the same as *Syntax classes, but are named differently because they're only needed because we can't put anything new inside existing *Syntax classes without breaking binary compatability.

With that said, I actually think you can drop them right here in this FoldableOps class:
https://github.com/typelevel/cats/blob/master/core/src/main/scala/cats/syntax/foldable.scala#L116

You could look at this PR for inspiration: #2366 :)

@leusgalvan
Copy link
Contributor

I've had more time to work on this and I'm almost finished adding the implementations to Reducible, Foldable and UnorderedFoldable.

I added the [max/min]ByOption to both Foldable and UnorderedFoldable through syntax. I provided the overriden implementation in Foldable because there I can use reduceLeftOption not available in UnorderedFoldable.

However, for cases where a type is both Foldable and UnorderedFoldable (e.g. List) the [max/min]ByOption methods are ambigous (they can be reached through either of the conversions).

What is the best way to handle this? I don't like the solutions I can think of: remove the implementation from Foldable or rename the methods in Unfoldable with unordered[max/min]ByOption.

@joroKr21
Copy link
Member

joroKr21 commented Sep 9, 2019

@leusgalvan I found myself needing this very often. I mean one can just pass an Order.by explicitly but it's a thorn in my eye. Idk if you're still working on this but how about adding them just to Foldable for the time being? Otherwise it would be inconsistent to have minimumByOption but no minimumOption in UnorderedFoldable. We can then have a separate issue for moving those up to UnorderedFoldable in the next breaking release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants