Function malachite_base::iterators::nonzero_values
source · pub const fn nonzero_values<I: Iterator>(xs: I) -> NonzeroValues<I> ⓘ
Expand description
Returns an iterator that generates all the nonzero values of a provided iterator.
nonzero_values(xs)
generates the same values as xs.filter(|x| x != I::Item::ZERO)
, but its
type is easier to work with.
This iterator will hang if given an iterator that produces an infinite suffix of zeros.
The output length is the number of nonzero values produced by xs
.
§Examples
use itertools::Itertools;
use malachite_base::iterators::nonzero_values;
assert_eq!(
nonzero_values([-3i8, -2, -1, 0, 1, 2, 3].iter().cloned()).collect_vec(),
&[-3, -2, -1, 1, 2, 3]
)