iter-extra
A Rust crate providing additional iterator methods for working with partial ordering, particularly useful when dealing with floating-point numbers and other types that implement PartialOrd but not Ord.
Features
min_by_partial_key- Find the minimum element using a key function with partial orderingmax_by_partial_key- Find the maximum element using a key function with partial ordering- Handles NaN values gracefully by treating them as equal during comparisons
- Works with any iterator type through a blanket implementation
- Gradually extended with things we don't want to re-implement
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Usage
use *;
// Basic usage with floating-point numbers
let numbers = vec!;
assert_eq!;
let max = numbers.iter.max_by_partial_key;
assert_eq!;
// Works with NaN values
let with_nan = vec!;
let min = with_nan.iter.min_by_partial_key;
assert_eq!;
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.