orx_parallel/generic_iterator/
early_exit.rs

1use super::iter::GenericIterator;
2use crate::{IterationOrder, ParIter};
3
4impl<T, S, R, O> GenericIterator<T, S, R, O>
5where
6    T: Send + Sync,
7    S: Iterator<Item = T>,
8    R: rayon::iter::ParallelIterator<Item = T>,
9    O: ParIter<Item = T>,
10{
11    /// Find computation for the generic iterator.
12    ///
13    /// See [`find`] for details.
14    ///
15    /// [`find`]: crate::ParIter::find
16    pub fn find<Predicate>(self, predicate: Predicate) -> Option<T>
17    where
18        Predicate: Fn(&T) -> bool + Send + Sync + Clone,
19    {
20        match self {
21            GenericIterator::Sequential(mut x) => x.find(predicate),
22            GenericIterator::Rayon(x) => x.find_first(predicate),
23            GenericIterator::Orx(x) => x.find(predicate),
24        }
25    }
26
27    /// Find-any computation for the generic iterator.
28    ///
29    /// See [`first`] for details.
30    ///
31    /// [`first`]: crate::ParIter::first
32    pub fn find_any<Predicate>(self, predicate: Predicate) -> Option<T>
33    where
34        Predicate: Fn(&T) -> bool + Send + Sync + Clone,
35    {
36        match self {
37            GenericIterator::Sequential(mut x) => x.find(predicate),
38            GenericIterator::Rayon(x) => x.find_any(predicate),
39            GenericIterator::Orx(x) => x.iteration_order(IterationOrder::Arbitrary).find(predicate),
40        }
41    }
42}