question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

github_iconTop GitHub Comments

StefanBertelscommented, Feb 7, 2018

Thanks. I agree. Just one point: I suggest returning first element on equality always. (stable order)

0reactions
louthycommented, Feb 7, 2018

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 every Ord 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 and max relatively easily to the Prelude though:

public static A min<OrdA, A>(A x, A y) where OrdA : struct, Ord<A> =>
    compare<OrdA, A>(x, y) < 0
        ? x
        : y;

public static A max<OrdA, A>(A x, A y) where OrdA : struct, Ord<A> =>
    compare<OrdA, A>(x, y) > 0
        ? x
        : y;

public static A min<OrdA, A>(A x, A y, A z, params A[] tail) where OrdA : struct, Ord<A> =>
    fold<MArray<A>, A[], A, A>(tail, min<OrdA, A>(x, min<OrdA, A>(y, z)), min<OrdA, A>);

public static A max<OrdA, A>(A x, A y, A z, params A[] tail) where OrdA : struct, Ord<A> =>
    fold<MArray<A>, A[], A, A>(tail, max<OrdA, A>(x, max<OrdA, A>(y, z)), max<OrdA, A>);

In fact I’ve just done it (it’s on v2.2.5-beta)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found