itertools
itertools copied to clipboard
Proposed method: all_equal_value`
It'd be nice to have a version of all_equal that returns the value in the iterator where all the items in the iterator compare equal to that value. Proposed implementation:
/// Return the first item in the iterator if it compares equal to all the other
/// items in the iterator. Return `None` if the iterator is empty, or if it
/// contains any items that do not equal the first item.
fn all_equal_value(mut self) -> Option<Self::Item> {
let first = self.next()?;
if self.all(|item| first == item) {
Some(first)
} else {
None
}
}
Sounds like a nice complement to https://github.com/rust-itertools/itertools/pull/241!