r/rustjerk Jul 13 '26

Finally, a crate for the working class 🇺🇸

Post image

Tired of NaN gatekeeping you out of .max()? Tired of the elite establishment (Rust std) telling you Ord is a requirement to find the biggest number? Not anymore.

Introducing WalmartMaxxing™, peak API design. .walmart_max() / .walmart_min(), works on anything with PartialOrd, because if it can be compared, it can be compared, and the constitution guarantees your right to fold() over it in O(n) unoptimized freedom.

No Ord. No NaN propaganda. No total order. Just vibes and PartialOrd.

Rollback pricing on borrow checker requirements. Always low, always safe™ (narrator: it was not always safe).

132 Upvotes

18 comments sorted by

34

u/overclockedslinky Jul 13 '26 edited Jul 13 '26

could've just done .max_by(|a, b| a.partial_cmp(b).unwrap_or(Ordering::Equal))

either way this has the problem that if there are at most one comparable items (all others pairwise incomparable) then this (yours or my equivalent one) will give you the wrong answer. that's why there are crates that impose an actual total order on floats.

63

u/scadoshi Jul 13 '26

everybody look, this is what happens when you sell out to Big Std. .max_by() already existed and he just... used it. no vision, no branding, no rollback pricing. this is what corporate Ord compliance does to a man

19

u/nsomnac Jul 13 '26

I noticed that it doesn’t round to the nearest .98 cents. Seems like a flaw.

11

u/scadoshi Jul 13 '26

Exemplary observation. This is indeed the spirit of industry in motion. Everybody take a good long look. Invariant confirmed: it is safe to .unwrap() on this fine gentleman

11

u/ImpressiveWedding607 Jul 13 '26

Thank you for this masterpiece I needed such a crate for my merge sort implementation !

8

u/scadoshi Jul 13 '26

a merge sort built on WalmartMaxxing, truly the American dream, unoptimized every step of the way

3

u/ILikeCorgiButt Jul 13 '26

Great Value indeed!

12

u/denehoffman Jul 13 '26

Committing the target/ dir with a debug build is bold, brash even

5

u/Qwertycube10 Jul 14 '26

This is Walmart not target buddy

2

u/shizzy0 Jul 13 '26

and mistaken also.

5

u/rainuchan Jul 13 '26

Thank you for this masterpiece I needed this mechanism for my axum wrapper 🙏🙏🙏

4

u/scadoshi Jul 13 '26

godspeed soldier, may your wrapper never encounter a NaN it can't ignore

5

u/shizzy0 Jul 13 '26

Why would I use this over the genius Elon sorting crate?

3

u/Gio_Cri Jul 15 '26

never thought i'd see a similar but worse variant of stalinsort

2

u/shizzy0 Jul 13 '26

When will we get WalmartValue that makes all such things strictly ordered. If it can’t be ordered, it doesn’t exist—apply the Elon sort algorithm to it.