|
|
|
|
|
by yorwba
3325 days ago
|
|
Not all partial orders have well-defined min/max, though. Ideally, you would want traits for meet/join semi-lattices, but I'm not sure how much abstract algebra you can inflict on the average Rustacean. Then there is the whole problem of NaN is incomparable with everything, so you'd have to use a non-standard definition of semi-lattice to allow for that. And do you want max(NaN, 0) to be NaN or 0? There is a case to be made for either possibility. |
|
Then again according to float semantics, sum of a list containing NaN must be NaN, so it would make sense to extend that principle to min/max.
But the naive implementation of min/max will never output NaN because NaN always compares false. (... unless NaN is the first element. ugly.)
Maybe making it explicit would be best: Make an explicit fn for float collections that filters out NaN in an Iterator, then claim that Item is totally ordered. I'm too much of a rust noob to know if this is possible. (playground here I come!)