rust-itertools / itertools

Extra iterator adaptors, iterator methods, free functions, and macros.
https://docs.rs/itertools/
Apache License 2.0
2.72k stars 309 forks source link

Add min/max to same-element <T: Ord> EitherOrBoth #690

Closed 2ndDerivative closed 1 year ago

2ndDerivative commented 1 year ago

Had the idea of this low-cost quality of life implementation on EitherOrBoth. Please give any feedback you have! Cheers!

phimuemue commented 1 year ago

Hi there and thank you for the idea.

I am unsure if min/max are special enough to justify the existence of auxiliary methods for them, so I thought about generalizing this and offering a function that the user can plug in min/Max/anything else into...

... just to find out this already exists: https://docs.rs/itertools/latest/itertools/enum.EitherOrBoth.html#method.reduce

So my personal take on this would be to go without the specific min/max unless we have evidence that users really need this.

2ndDerivative commented 1 year ago

I saw that function too and the formulation of "Product" did not prepare me for what exactly it does. I thought it was about multiplication and was kind of irritated. I agree with the sentiment of not implementing this then, but would probably suggest improving the documentation for reduce()