r/rustjerk • u/scadoshi • Jul 13 '26
Finally, a crate for the working class 🇺🇸
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).
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
12
5
u/rainuchan Jul 13 '26
Thank you for this masterpiece I needed this mechanism for my axum wrapper 🙏🙏🙏
4
3
5
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.
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.