Trait tor_basic_utils::iter::IteratorExt

source ·
pub trait IteratorExt: Iterator {
    // Provided method
    fn filter_cnt<P>(
        self,
        count: &mut FilterCount,
        pred: P
    ) -> CountingFilter<'_, P, Self> 
       where Self: Sized,
             P: FnMut(&Self::Item) -> bool { ... }
}
Expand description

Iterator extension trait to implement a counting filter.

Provided Methods§

source

fn filter_cnt<P>( self, count: &mut FilterCount, pred: P ) -> CountingFilter<'_, P, Self>
where Self: Sized, P: FnMut(&Self::Item) -> bool,

Return an iterator that contains every member of this iterator, and which records its progress in count.

The values in count are initially set to zero. Then, every time the filter considers an item, it will either increment count.n_accepted or count.n_rejected.

Note that if the iterator is dropped before it is exhausted, the count will not be complete.

§Examples
use tor_basic_utils::iter::{IteratorExt, FilterCount};

let mut count = FilterCount::default();
let emoji : String = "Hello 🙂 World 🌏!"
    .chars()
    .filter_cnt(&mut count, |ch| !ch.is_ascii())
    .collect();
assert_eq!(emoji, "🙂🌏");
assert_eq!(count, FilterCount { n_accepted: 2, n_rejected: 14});

Implementors§

source§

impl<I> IteratorExt for I
where I: Iterator,