Function malachite_base::iterators::is_unique
source · pub fn is_unique<I: Iterator>(xs: I) -> bool
Expand description
Returns whether an iterator never returns the same value twice.
is_unique(xs)
is equivalent to xs.unique().count() <= 1
for finite iterators, but is more
efficient and doesn’t hang if provided a non-unique infinite iterator.
This iterator will hang if given an infinite unique iterator.
§Examples
use malachite_base::iterators::is_unique;
let empty: [u32; 0] = [];
assert_eq!(is_unique(empty.iter()), true);
assert_eq!(is_unique([1, 2, 3, 4].iter()), true);
assert_eq!(is_unique([1, 2, 3, 1].iter()), false);
assert_eq!(is_unique((0..).map(|i| i / 2)), false);