pub fn iter_with_counts<V: PartialEq>(
source: impl Iterator<Item = V>,
) -> impl Iterator<Item = (V, u64)>Expand description
Transforms an iterator of values into an iterator of value-count pairs.
The pairs of type (V, u64) are such that:
- Each pair corresponds to a grouping of the contiguous items from
sourcethat have the same value. - The pair’s first component is the value from
source. - The pair’s second component is the count of items from
sourcein the grouping.
§Example
use basic_stats::core::iter_with_counts;
fn main() {
let dat = [1., 3., 9., 9., 10., 10., 10., 10., 20.];
let dat_c = iter_with_counts(dat.into_iter()).collect::<Vec<_>>();
let exp_dat_c = vec![(1., 1), (3., 1), (9., 2), (10., 4), (20., 1)];
assert_eq!(exp_dat_c, dat_c);
println!("success");
}