Skip to main content

ParUseOption

Trait ParUseOption 

Source
pub trait ParUseOption: Sized + ParUseOptionCore {
Show 32 methods // Required methods fn runner<Q: ParRunner>( self, runner: Q, ) -> impl ParUseOption<Elem = Self::Elem, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = Self::Xap2, Input = Self::Input, Size = Self::Size>; fn runner_with_diagnostics( self, ) -> impl ParUseOption<Elem = Self::Elem, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = Self::Xap2, Input = Self::Input, Size = Self::Size>; fn num_threads(self, num_threads: impl Into<NumThreads>) -> Self; fn chunk_size(self, chunk_size: impl Into<ChunkSize>) -> Self; fn iteration_order(self, iteration_order: IterationOrder) -> Self; fn map<Q, H>( self, h: H, ) -> impl ParUseOption<Elem = Q, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = <<Self::Xap2 as XapUse>::Size as Size>::UMap<Self::Xap2, Q, H>, Input = Self::Input, Size = Self::Size> where H: Fn(&mut Self::Use, Self::Elem) -> Q + Copy + Send; fn inspect<H>( self, h: H, ) -> impl ParUseOption<Elem = Self::Elem, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = <<Self::Xap2 as XapUse>::Size as Size>::UInspect<Self::Xap2, H>, Input = Self::Input, Size = Self::Size> where H: Fn(&mut Self::Use, &Self::Elem) + Copy + Send; fn filter<H>( self, h: H, ) -> impl ParUseOption<Elem = Self::Elem, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = <<Self::Xap2 as XapUse>::Size as Size>::UFilter<Self::Xap2, H>, Input = Self::Input, Size = <Self::Size as SizePair>::ThenBin> where H: Fn(&mut Self::Use, &Self::Elem) -> bool + Copy + Send; fn filter_map<Q, H>( self, h: H, ) -> impl ParUseOption<Elem = Q, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = <<Self::Xap2 as XapUse>::Size as Size>::UFilterMap<Self::Xap2, Q, H>, Input = Self::Input, Size = <Self::Size as SizePair>::ThenBin> where H: Fn(&mut Self::Use, Self::Elem) -> Option<Q> + Copy + Send; fn flat_map<V, H>( self, h: H, ) -> impl ParUseOption<Elem = V::Item, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = <<Self::Xap2 as XapUse>::Size as Size>::UFlatMap<Self::Xap2, V, H>, Input = Self::Input, Size = <Self::Size as SizePair>::ThenMany> where V: IntoIterator, H: Fn(&mut Self::Use, Self::Elem) -> V + Copy + Send; fn flatten( self, ) -> impl ParUseOption<Elem = <Self::Elem as IntoIterator>::Item, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = <<Self::Xap2 as XapUse>::Size as Size>::UFlatten<Self::Xap2>, Input = Self::Input, Size = <Self::Size as SizePair>::ThenMany> where Self::Elem: IntoIterator; fn size_hint(&self) -> (usize, Option<usize>); fn first(self) -> Option<Option<Self::Elem>> where Self::Elem: Send; fn reduce<F>(self, f: F) -> Option<Option<Self::Elem>> where F: Fn(&mut Self::Use, Self::Elem, Self::Elem) -> Self::Elem + Send + Copy, Self::Elem: Send; fn collect_into<P>(self, dst: &mut P) -> Option<()> where P: ParExtend<Self::Elem>, Self::Elem: Send; // Provided methods fn copied<'a, O>( self, ) -> impl ParUseOption<Elem = O, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = <<Self::Xap2 as XapUse>::Size as Size>::UMapped<Self::Xap2, UFnCopied<'a, Self::Use, O>>, Input = Self::Input, Size = Self::Size> where Self: ParUseOption<Elem = &'a O>, O: Copy + 'a, Self::Use: 'a { ... } fn cloned<'a, O>( self, ) -> impl ParUseOption<Elem = O, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = <<Self::Xap2 as XapUse>::Size as Size>::UMapped<Self::Xap2, UFnCloned<'a, Self::Use, O>>, Input = Self::Input, Size = Self::Size> where Self: ParUseOption<Elem = &'a O>, O: Clone + 'a, Self::Use: 'a { ... } fn len(&self) -> usize where Self::Input: ExactSizeConcurrentIter, Self: ParUseOption<Size = OneOne> { ... } fn is_empty(&self) -> bool where Self::Input: ExactSizeConcurrentIter, Self: ParUseOption<Size = OneOne> { ... } fn collect<P>(self) -> Option<P> where P: ParExtend<Self::Elem> + Default, Self::Elem: Send { ... } fn all<F>(self, f: F) -> Option<bool> where Self::Elem: Send, F: Fn(&mut Self::Use, &Self::Elem) -> bool + Sync { ... } fn any<F>(self, f: F) -> Option<bool> where Self::Elem: Send, F: Fn(&mut Self::Use, &Self::Elem) -> bool + Sync { ... } fn count(self) -> Option<usize> { ... } fn find<F>(self, f: F) -> Option<Option<Self::Elem>> where Self::Elem: Send, F: Fn(&mut Self::Use, &Self::Elem) -> bool + Sync { ... } fn for_each<F>(self, f: F) -> Option<()> where F: Fn(&mut Self::Use, Self::Elem) + Send + Copy { ... } fn max(self) -> Option<Option<Self::Elem>> where Self::Elem: Ord + Send { ... } fn max_by<F>(self, f: F) -> Option<Option<Self::Elem>> where Self::Elem: Send, F: Fn(&mut Self::Use, &Self::Elem, &Self::Elem) -> Ordering + Sync { ... } fn max_by_key<B, F>(self, f: F) -> Option<Option<Self::Elem>> where Self::Elem: Send, B: Ord, F: Fn(&mut Self::Use, &Self::Elem) -> B + Sync { ... } fn min(self) -> Option<Option<Self::Elem>> where Self::Elem: Ord + Send { ... } fn min_by<F>(self, f: F) -> Option<Option<Self::Elem>> where Self::Elem: Send, F: Fn(&mut Self::Use, &Self::Elem, &Self::Elem) -> Ordering + Sync { ... } fn min_by_key<B, F>(self, f: F) -> Option<Option<Self::Elem>> where Self::Elem: Send, B: Ord, F: Fn(&mut Self::Use, &Self::Elem) -> B + Sync { ... } fn sum<S>(self) -> Option<S> where Self::Elem: Sum<S>, S: Send { ... }
}
Expand description

Fallible parallel iterator with worker-local mutable state.

ParUseOption combines:

  • fallible processing (Option-based short-circuiting), and
  • mutable worker-local state (&mut Use passed to closures).

You can enter this mode from ParOption via use_new, use_vec, or use_slice.

Similar to using ?, this trait keeps pipeline logic focused on successful values while the computation short-circuits to None when any element evaluates to None.

Related traits:

  • ParOption for Option-fallible pipelines without worker-local state,
  • ParUse for worker-local state in infallible pipelines.

§Examples

Reusing a per-worker buffer:

use core::fmt::Write;
use orx_parallel::*;

let out: Option<Vec<usize>> = (0..16usize)
    .into_par()
    .map(Some)
    .into_optional()
    .use_new(|_| String::with_capacity(32))
    .map(|buffer, x| {
        buffer.clear();
        write!(buffer, "{x}").unwrap();
        buffer.parse::<usize>().unwrap()
    })
    .collect();

assert_eq!(out, Some((0..16).collect::<Vec<_>>()));

Using RNG as mutable worker-local state:

use orx_parallel::*;
use rand::prelude::*;
use rand_chacha::ChaCha8Rng;

let out: Option<Vec<usize>> = (0..32usize)
    .into_par()
    .map(Some)
    .into_optional()
    .use_new(|thread_idx| ChaCha8Rng::seed_from_u64(100 + thread_idx as u64))
    .map(|rng, x| x + rng.random_range(0..10))
    .collect();

assert_eq!(out.as_ref().map(Vec::len), Some(32));
assert!(out.unwrap().into_iter().enumerate().all(|(i, v)| v >= i));

Required Methods§

Source

fn runner<Q: ParRunner>( self, runner: Q, ) -> impl ParUseOption<Elem = Self::Elem, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = Self::Xap2, Input = Self::Input, Size = Self::Size>

Replaces the current parallel runner with runner.

§Examples
use orx_parallel::*;

let par = ["1", "2", "3"]
    .into_par()
    .map(|s| s.parse::<usize>().ok())
    .into_optional()
    .use_new(|_| ());

let par = par.runner(Runner::fixed());

let out: Option<Vec<_>> = par.collect();
assert_eq!(out, Some(vec![1, 2, 3]));
Source

fn runner_with_diagnostics( self, ) -> impl ParUseOption<Elem = Self::Elem, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = Self::Xap2, Input = Self::Input, Size = Self::Size>

Wraps the current runner with diagnostics-enabled execution.

§Examples
use orx_parallel::*;

let par = ["1", "2", "3"]
    .into_par()
    .map(|s| s.parse::<usize>().ok())
    .into_optional()
    .use_new(|_| ());

#[cfg(feature = "std")]
let par = par.runner_with_diagnostics();

let out: Option<Vec<_>> = par.collect();
assert_eq!(out, Some(vec![1, 2, 3]));
Source

fn num_threads(self, num_threads: impl Into<NumThreads>) -> Self

Sets the maximum number of worker threads for this computation.

§Examples
use orx_parallel::*;

let out: Option<Vec<_>> = (1..6)
    .into_par()
    .map(Some)
    .into_optional()
    .use_new(|_| ())
    .num_threads(1)
    .collect();

assert_eq!(out, Some(vec![1, 2, 3, 4, 5]));
Source

fn chunk_size(self, chunk_size: impl Into<ChunkSize>) -> Self

Sets chunk size used when pulling items from the concurrent input.

§Examples
use orx_parallel::*;

let out: Option<Vec<_>> = (0..8)
    .into_par()
    .map(Some)
    .into_optional()
    .use_new(|_| ())
    .chunk_size(2)
    .collect();

assert_eq!(out, Some((0..8).collect::<Vec<_>>()));
Source

fn iteration_order(self, iteration_order: IterationOrder) -> Self

Sets iteration-order semantics for order-sensitive operations.

§Examples
use orx_parallel::*;

let ordered = (1..10_000)
    .into_par()
    .map(Some)
    .into_optional()
    .use_new(|_| ())
    .iteration_order(IterationOrder::Ordered)
    .find(|_, x| x % 3421 == 0);
assert_eq!(ordered, Some(Some(3421)));
Source

fn map<Q, H>( self, h: H, ) -> impl ParUseOption<Elem = Q, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = <<Self::Xap2 as XapUse>::Size as Size>::UMap<Self::Xap2, Q, H>, Input = Self::Input, Size = Self::Size>
where H: Fn(&mut Self::Use, Self::Elem) -> Q + Copy + Send,

Maps each successful element with closure h.

§Examples
use orx_parallel::*;

let out: Option<Vec<_>> = (1..4)
    .into_par()
    .map(Some)
    .into_optional()
    .use_new(|_| ())
    .map(|_, x| 2 * x)
    .collect();

assert_eq!(out, Some(vec![2, 4, 6]));
Source

fn inspect<H>( self, h: H, ) -> impl ParUseOption<Elem = Self::Elem, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = <<Self::Xap2 as XapUse>::Size as Size>::UInspect<Self::Xap2, H>, Input = Self::Input, Size = Self::Size>
where H: Fn(&mut Self::Use, &Self::Elem) + Copy + Send,

Runs h on each successful element and forwards the item unchanged.

§Examples
use orx_parallel::*;

let mut use_vec = UseVec::new(|_| 0usize);
let out: Option<Vec<_>> = (1..5)
    .into_par()
    .map(Some)
    .into_optional()
    .use_vec(&mut use_vec)
    .inspect(|count, _| *count += 1)
    .collect();

assert_eq!(out, Some(vec![1, 2, 3, 4]));
assert_eq!(use_vec.into_vec().into_iter().sum::<usize>(), 4);
Source

fn filter<H>( self, h: H, ) -> impl ParUseOption<Elem = Self::Elem, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = <<Self::Xap2 as XapUse>::Size as Size>::UFilter<Self::Xap2, H>, Input = Self::Input, Size = <Self::Size as SizePair>::ThenBin>
where H: Fn(&mut Self::Use, &Self::Elem) -> bool + Copy + Send,

Keeps successful elements satisfying predicate h.

§Examples
use orx_parallel::*;

let out: Option<Vec<_>> = (1..7)
    .into_par()
    .map(Some)
    .into_optional()
    .use_new(|_| ())
    .filter(|_, x| x % 2 == 1)
    .collect();

assert_eq!(out, Some(vec![1, 3, 5]));
Source

fn filter_map<Q, H>( self, h: H, ) -> impl ParUseOption<Elem = Q, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = <<Self::Xap2 as XapUse>::Size as Size>::UFilterMap<Self::Xap2, Q, H>, Input = Self::Input, Size = <Self::Size as SizePair>::ThenBin>
where H: Fn(&mut Self::Use, Self::Elem) -> Option<Q> + Copy + Send,

Maps and filters successful elements in one pass.

§Examples
use orx_parallel::*;

let out: Option<Vec<_>> = ["1", "x", "5"]
    .into_par()
    .map(|s| Some(s))
    .into_optional()
    .use_new(|_| ())
    .filter_map(|_, s| s.parse::<usize>().ok())
    .collect();

assert_eq!(out, Some(vec![1, 5]));
Source

fn flat_map<V, H>( self, h: H, ) -> impl ParUseOption<Elem = V::Item, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = <<Self::Xap2 as XapUse>::Size as Size>::UFlatMap<Self::Xap2, V, H>, Input = Self::Input, Size = <Self::Size as SizePair>::ThenMany>
where V: IntoIterator, H: Fn(&mut Self::Use, Self::Elem) -> V + Copy + Send,

Maps each successful element to an iterator and flattens one level.

§Examples
use orx_parallel::*;

let out: Option<Vec<_>> = (1..4)
    .into_par()
    .map(Some)
    .into_optional()
    .use_new(|_| ())
    .flat_map(|_, x| [x, x + 10])
    .collect();

assert_eq!(out, Some(vec![1, 11, 2, 12, 3, 13]));
Source

fn flatten( self, ) -> impl ParUseOption<Elem = <Self::Elem as IntoIterator>::Item, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = <<Self::Xap2 as XapUse>::Size as Size>::UFlatten<Self::Xap2>, Input = Self::Input, Size = <Self::Size as SizePair>::ThenMany>
where Self::Elem: IntoIterator,

Flattens one level of nested iterables on the success path.

§Examples
use orx_parallel::*;

let nested = vec![vec![1, 2], vec![3, 4]];
let out: Option<Vec<_>> = nested
    .into_par()
    .map(Some)
    .into_optional()
    .use_new(|_| ())
    .flatten()
    .collect();

assert_eq!(out, Some(vec![1, 2, 3, 4]));
Source

fn size_hint(&self) -> (usize, Option<usize>)

Returns a lower and optional upper bound on the number of successful output items.

The bounds follow the usual Iterator::size_hint convention. The upper bound includes items that may be removed by filtering or short-circuiting.

§Examples
use orx_parallel::*;

let values = (0..4)
    .into_par()
    .map(Some)
    .into_optional()
    .use_new(|_| ())
    .filter(|_, x| x % 2 == 0);

assert_eq!(values.size_hint(), (0, Some(4)));
Source

fn first(self) -> Option<Option<Self::Elem>>
where Self::Elem: Send,

Returns the first successful item according to iteration order.

Returns:

  • None if computation short-circuits due to a failure
  • Some(None) if no successful element exists
  • Some(Some(x)) for the first successful element
§Examples
use orx_parallel::*;

let ok = (1..4)
    .into_par()
    .map(Some)
    .into_optional()
    .use_new(|_| ())
    .first();
assert_eq!(ok, Some(Some(1)));

let fail = vec![None, Some(1), Some(3)]
    .into_par()
    .into_optional()
    .use_new(|_| ())
    .first();
assert_eq!(fail, None);
Source

fn reduce<F>(self, f: F) -> Option<Option<Self::Elem>>
where F: Fn(&mut Self::Use, Self::Elem, Self::Elem) -> Self::Elem + Send + Copy, Self::Elem: Send,

Reduces successful items into one value using f.

Returns None on short-circuit failure.

§Examples
use orx_parallel::*;

let ok = (1..6)
    .into_par()
    .map(Some)
    .into_optional()
    .use_new(|_| ())
    .reduce(|_, a, b| a + b);
assert_eq!(ok, Some(Some(15)));

let fail = vec![Some(1), None, Some(3)]
    .into_par()
    .into_optional()
    .use_new(|_| ())
    .reduce(|_, a, b| a + b);
assert_eq!(fail, None);
Source

fn collect_into<P>(self, dst: &mut P) -> Option<()>
where P: ParExtend<Self::Elem>, Self::Elem: Send,

Collects successful items into dst.

Returns None on short-circuit failure.

§Examples
use orx_parallel::*;

let mut dst = vec![10usize];
let ok = (0..3)
    .into_par()
    .map(Some)
    .into_optional()
    .use_new(|_| ())
    .collect_into(&mut dst);
assert_eq!(ok, Some(()));
assert_eq!(dst, vec![10, 0, 1, 2]);

Provided Methods§

Source

fn copied<'a, O>( self, ) -> impl ParUseOption<Elem = O, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = <<Self::Xap2 as XapUse>::Size as Size>::UMapped<Self::Xap2, UFnCopied<'a, Self::Use, O>>, Input = Self::Input, Size = Self::Size>
where Self: ParUseOption<Elem = &'a O>, O: Copy + 'a, Self::Use: 'a,

Copies elements of a reference iterator on the success path.

§Examples
use orx_parallel::*;

let data = vec![1, 2, 3];
let out: Option<Vec<_>> = data
    .par()
    .map(Some)
    .into_optional()
    .use_new(|_| ())
    .copied()
    .collect();

assert_eq!(out, Some(vec![1, 2, 3]));
Source

fn cloned<'a, O>( self, ) -> impl ParUseOption<Elem = O, Use = Self::Use, Xap1 = Self::Xap1, M = Self::M, Xap2 = <<Self::Xap2 as XapUse>::Size as Size>::UMapped<Self::Xap2, UFnCloned<'a, Self::Use, O>>, Input = Self::Input, Size = Self::Size>
where Self: ParUseOption<Elem = &'a O>, O: Clone + 'a, Self::Use: 'a,

Clones elements of a reference iterator on the success path.

§Examples
use orx_parallel::*;

let data = vec!["a".to_string(), "b".to_string()];
let out: Option<Vec<_>> = data
    .par()
    .map(Some)
    .into_optional()
    .use_new(|_| ())
    .cloned()
    .collect();

assert_eq!(out, Some(vec!["a".to_string(), "b".to_string()]));
Source

fn len(&self) -> usize
where Self::Input: ExactSizeConcurrentIter, Self: ParUseOption<Size = OneOne>,

Returns the exact number of output items.

Source

fn is_empty(&self) -> bool
where Self::Input: ExactSizeConcurrentIter, Self: ParUseOption<Size = OneOne>,

Returns true when the parallel iterator has no output items.

Source

fn collect<P>(self) -> Option<P>
where P: ParExtend<Self::Elem> + Default, Self::Elem: Send,

Collects successful items into a new collection.

Returns None on short-circuit failure.

§Examples
use orx_parallel::*;

let out: Option<Vec<_>> = (1..4)
    .into_par()
    .map(Some)
    .into_optional()
    .use_new(|_| ())
    .collect();

assert_eq!(out, Some(vec![1, 2, 3]));
Source

fn all<F>(self, f: F) -> Option<bool>
where Self::Elem: Send, F: Fn(&mut Self::Use, &Self::Elem) -> bool + Sync,

Returns Some(true) if all successful items satisfy f.

Returns None on short-circuit failure.

§Examples
use orx_parallel::*;

let ok = (1..5)
    .into_par()
    .map(Some)
    .into_optional()
    .use_new(|_| ())
    .all(|_, x| x > &0);
assert_eq!(ok, Some(true));

let fail = vec![Some(1), None, Some(3)]
    .into_par()
    .into_optional()
    .use_new(|_| ())
    .all(|_, x| x > &0);
assert_eq!(fail, None);
Source

fn any<F>(self, f: F) -> Option<bool>
where Self::Elem: Send, F: Fn(&mut Self::Use, &Self::Elem) -> bool + Sync,

Returns Some(true) if any successful item satisfies f.

Returns None on short-circuit failure.

§Examples
use orx_parallel::*;

let ok = (1..5)
    .into_par()
    .map(Some)
    .into_optional()
    .use_new(|_| ())
    .any(|_, x| x % 2 == 0);
assert_eq!(ok, Some(true));

let fail = vec![Some(1), None, Some(3)]
    .into_par()
    .into_optional()
    .use_new(|_| ())
    .any(|_, x| x % 2 == 0);
assert_eq!(fail, None);
Source

fn count(self) -> Option<usize>

Counts successful elements.

Returns None on short-circuit failure.

§Examples
use orx_parallel::*;

let ok = (1..11)
    .into_par()
    .map(Some)
    .into_optional()
    .use_new(|_| ())
    .filter(|_, x| x % 3 == 0)
    .count();
assert_eq!(ok, Some(3));
Source

fn find<F>(self, f: F) -> Option<Option<Self::Elem>>
where Self::Elem: Send, F: Fn(&mut Self::Use, &Self::Elem) -> bool + Sync,

Finds first (ordered) or any (arbitrary) successful item satisfying f.

Returns None on short-circuit failure.

§Examples
use orx_parallel::*;

let found = (1..101)
    .into_par()
    .map(Some)
    .into_optional()
    .use_new(|_| ())
    .find(|_, x| x % 17 == 0);
assert_eq!(found, Some(Some(17)));
Source

fn for_each<F>(self, f: F) -> Option<()>
where F: Fn(&mut Self::Use, Self::Elem) + Send + Copy,

Executes f for each successful element.

Returns None on short-circuit failure.

§Examples
use orx_parallel::*;

let mut sums = UseVec::new(|_| 0usize);

let result = (1..5)
    .into_par()
    .map(Some)
    .into_optional()
    .use_vec(&mut sums)
    .for_each(|local, x| *local += x);

assert_eq!(result, Some(()));
assert_eq!(sums.into_vec().into_iter().sum::<usize>(), 10);
Source

fn max(self) -> Option<Option<Self::Elem>>
where Self::Elem: Ord + Send,

Returns maximum successful element.

Returns None on short-circuit failure.

§Examples
use orx_parallel::*;

let m = (1..5)
    .into_par()
    .map(Some)
    .into_optional()
    .use_new(|_| ())
    .max();
assert_eq!(m, Some(Some(4)));
Source

fn max_by<F>(self, f: F) -> Option<Option<Self::Elem>>
where Self::Elem: Send, F: Fn(&mut Self::Use, &Self::Elem, &Self::Elem) -> Ordering + Sync,

Returns successful element considered maximum by comparator f.

Returns None on short-circuit failure.

§Examples
use orx_parallel::*;

let x = vec![-3_i32, 0, 1, 5, -10]
    .into_par()
    .map(Some)
    .into_optional()
    .use_new(|_| ())
    .max_by(|_, a, b| a.cmp(b));
assert_eq!(x, Some(Some(5)));
Source

fn max_by_key<B, F>(self, f: F) -> Option<Option<Self::Elem>>
where Self::Elem: Send, B: Ord, F: Fn(&mut Self::Use, &Self::Elem) -> B + Sync,

Returns successful element with maximum key value.

Returns None on short-circuit failure.

§Examples
use orx_parallel::*;

let x = vec![-3_i32, 0, 1, 5, -10]
    .into_par()
    .map(Some)
    .into_optional()
    .use_new(|_| ())
    .max_by_key(|_, x| x.abs());
assert_eq!(x, Some(Some(-10)));
Source

fn min(self) -> Option<Option<Self::Elem>>
where Self::Elem: Ord + Send,

Returns minimum successful element.

Returns None on short-circuit failure.

§Examples
use orx_parallel::*;

let m = (1..5)
    .into_par()
    .map(Some)
    .into_optional()
    .use_new(|_| ())
    .min();
assert_eq!(m, Some(Some(1)));
Source

fn min_by<F>(self, f: F) -> Option<Option<Self::Elem>>
where Self::Elem: Send, F: Fn(&mut Self::Use, &Self::Elem, &Self::Elem) -> Ordering + Sync,

Returns successful element considered minimum by comparator f.

Returns None on short-circuit failure.

§Examples
use orx_parallel::*;

let x = vec![-3_i32, 0, 1, 5, -10]
    .into_par()
    .map(Some)
    .into_optional()
    .use_new(|_| ())
    .min_by(|_, a, b| a.cmp(b));
assert_eq!(x, Some(Some(-10)));
Source

fn min_by_key<B, F>(self, f: F) -> Option<Option<Self::Elem>>
where Self::Elem: Send, B: Ord, F: Fn(&mut Self::Use, &Self::Elem) -> B + Sync,

Returns successful element with minimum key value.

Returns None on short-circuit failure.

§Examples
use orx_parallel::*;

let x = vec![-3_i32, 0, 1, 5, -10]
    .into_par()
    .map(Some)
    .into_optional()
    .use_new(|_| ())
    .min_by_key(|_, x| x.abs());
assert_eq!(x, Some(Some(0)));
Source

fn sum<S>(self) -> Option<S>
where Self::Elem: Sum<S>, S: Send,

Sums successful elements using Sum implementation.

Returns None on short-circuit failure.

§Examples
use orx_parallel::*;

let s: Option<usize> = (1..5)
    .into_par()
    .map(Some)
    .into_optional()
    .use_new(|_| ())
    .sum();
assert_eq!(s, Some(10));

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§