orx-parallel 4.0.0

Performant parallel computations with an expressive iterator API.
Documentation
use crate::infallible::{ParIter, xap_variants::Id};
use crate::runner::default_runner;
use orx_concurrent_iter::{ConcurrentCollection, ConcurrentIterable};

/// A collection from which a parallel iterator can be created repeatedly
/// using `par()` method.
///
/// Sequential counterpart: `iter()`.
pub trait ParCollection: ConcurrentCollection {
    /// Returns a parallel iterator over shared references to collection items.
    ///
    /// # Example
    ///
    /// ```
    /// use orx_parallel::*;
    ///
    /// let values = vec![1, 2, 3, 4];
    ///
    /// let sum: i32 = ParCollection::par(&values).copied().sum();
    /// assert_eq!(sum, 10);
    ///
    /// // alternatively
    /// let sum: i32 = values.par().copied().sum();
    /// assert_eq!(sum, 10);
    /// ```
    fn par(&self) -> ParIter<<Self::Iterable<'_> as ConcurrentIterable>::Iter, Id<&Self::Item>> {
        ParIter::new(
            self.con_iter(),
            Id::new(),
            default_runner(),
            Default::default(),
        )
    }
}

impl<X> ParCollection for X where X: ConcurrentCollection {}