Function malachite_base::iterators::is_constant
source · pub fn is_constant<I: Iterator>(xs: I) -> bool
Expand description
Returns whether all of the values generated by an iterator are equal.
is_constant(xs)
is equivalent to xs.unique().count() == 1
for finite nonempty iterators, but
is more efficient, doesn’t require Clone
or Hash
implementations, and doesn’t hang if
provided an infinite non-constant iterator.
This function will hang if given an infinite constant iterator.
§Examples
use malachite_base::iterators::is_constant;
assert_eq!(is_constant([1; 4].iter()), true);
assert_eq!(is_constant([1, 2, 3, 4].iter()), false);
assert_eq!(is_constant(0..), false);