Skip to main content

IteratorExt

Trait IteratorExt 

Source
pub trait IteratorExt: Iterator {
    // Provided method
    fn all_same<F, T>(self, f: F) -> Option<T>
       where Self: Sized,
             F: FnMut(&Self::Item) -> T,
             T: Eq { ... }
}
Expand description

Extension trait for iterators to add utility methods

Provided Methods§

Source

fn all_same<F, T>(self, f: F) -> Option<T>
where Self: Sized, F: FnMut(&Self::Item) -> T, T: Eq,

Checks if all elements in the iterator have the same value when passed through the closure.

Returns Some(value) if all extracted values are equal, None otherwise. For empty iterators, returns None.

§Examples
use ark::util::IteratorExt;

let vec = vec![(1, "a"), (2, "a"), (3, "a")];
assert_eq!(vec.iter().all_same(|(_, s)| s), Some(&"a"));

let vec = vec![(1, "a"), (2, "b"), (3, "c")];
assert_eq!(vec.iter().all_same(|(_, s)| s), None);

Implementors§