Best / easiest way to get Min/Max via Ord<A>
See original GitHub issueQuestion: Could/should interface Ord contain method
[Pure]
A Min(A x, A y) => Compare(x, y) > 0 ? y : x
[Pure]
A Max(A x, A y) => Compare(x, y) < 0 ? y : x
Seems like this direct implementation in interface will be possible in future C# release. Currently interfaces have to be implemented in each implementing type.
This could be used as predicate for Reduce (and Fold) to get Min function on a sequence:
List("bla", "blub").Reduce(OrdStringOrdinalIgnoreCase.Inst.Min)
Or is there already something similar in LanguageExt?
(I thought about LINQ variant like list.OrderBy(…).First() but then I would need some OrderBy variant taking an Ord.)
My goals are: easy readable code (clear intent) and make use of ORD.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Whats the best way to kill Orda? : r/CODZombies
Your best way in killing it is with Stoner PAP 3 + Legendary and RoF. If you're trying to do challenges to kill...
Read more >SURVIVAL HUNTER GUIDE! - Talents, Rotation & More
FULL GUIDE! This guide is extremely in depth so I made the sections in the description so you can skip to whatever you...
Read more >4D v17 BETA STARTS TODAY!
ORDA provides simple methods to navigate through entities in an entity selection object, with many advantages. For example, you can handle ...
Read more >Backpage Com New City New York Escort
Find the Best Escort Service in Blue Ash Ohio on Backpage.com - Book Now! ... Permits you to temporarily mark select Posts for...
Read more >Find the Hottest Call Girls in Tonawanda New York - Satisfy ...
Here at Find Escorts you can discover the best female escorts for incall and outcall in Bishop's Stortford. What sort of men turn...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks. I agree. Just one point: I suggest returning first element on equality always. (stable order)
Hi Stefan, if you take a look at the Ord.Prelude.cs. You’ll see various functions for working with
Ord
. It doesn’t need to be in the interface itself as the behaviour is common to all types, and would add the burden of typing in the same method for everyOrd
class-instance. When default interface methods come along then there’s definitely an argument for adding more to the interface of the type-classes, but right now I don’t think it’s wise.We could add
min
andmax
relatively easily to thePrelude
though:In fact I’ve just done it (it’s on
v2.2.5-beta
)