pub fn matching_intervals_in_iterator<I: Iterator, F: Fn(&I::Item) -> bool>(
    xs: I,
    predicate: F
) -> Vec<(I::Item, I::Item)> where
    I::Item: Clone
Expand description

Groups elements of an iterator into intervals of adjacent elements that match a predicate. The endpoints of each interval are returned.

The intervals are inclusive.

This iterator will hang if given an infinite iterator.

Examples

use malachite_base::iterators::matching_intervals_in_iterator;

let xs = &[1, 2, 10, 11, 12, 7, 8, 16, 5];
assert_eq!(
    matching_intervals_in_iterator(xs.iter().cloned(), |&x| x >= 10).as_slice(),
    &[(10, 12), (16, 16)]
);
assert_eq!(
    matching_intervals_in_iterator(xs.iter().cloned(), |&x| x < 10).as_slice(),
    &[(1, 2), (7, 8), (5, 5)]
);