use std::cmp::{min, Ord, Ordering}; use crate::{Driver, Executor, ParallelIterator}; /* Min */ pub struct Min { iterator: X, } impl Min { pub fn new(iterator: X) -> Self { Self { iterator } } } impl<'a, X, T> Driver<'a, Option> for Min where X: ParallelIterator<'a, Item = T>, T: Send + Ord + 'a, { fn exec_with(self, executor: E) -> E::Result where E: Executor<'a, Option>, { self.iterator.reduce_with(min).exec_with(executor) } } /* MinBy */ pub struct MinBy { iterator: X, operation: O, } impl MinBy { pub fn new(iterator: X, operation: O) -> Self { Self { iterator, operation, } } } impl<'a, X, O, T> Driver<'a, Option> for MinBy where X: ParallelIterator<'a, Item = T>, O: Fn(&T, &T) -> Ordering + Clone + Send + Sync + 'a, T: Send + Ord + 'a, { fn exec_with(self, executor: E) -> E::Result where E: Executor<'a, Option>, { let operation = self.operation; self.iterator .reduce_with(move |a, b| match operation(&a, &b) { Ordering::Greater => b, _ => a, }) .exec_with(executor) } }