Trait aoko::standard::parallelisms::par_vec_ext::StdVecExt1[][src]

pub trait StdVecExt1<T> {
    fn for_each<R>(self, f: impl Fn(T) -> R + Sync + Send);
fn on_each<R>(self, f: impl Fn(&mut T) -> R + Sync + Send) -> Self;
fn filter(self, f: impl Fn(&T) -> bool + Sync + Send) -> Vec<T>;
fn fold(self, init: T, f: impl Fn(T, T) -> T + Sync + Send) -> T
    where
        T: Sync + Copy
;
fn reduce(self, f: impl Fn(T, T) -> T + Sync + Send) -> T
    where
        T: Sync + Copy + Default
;
fn sum(self) -> T
    where
        T: Sync + Copy + Default + Add<Output = T>
;
fn product(self) -> T
    where
        T: Product
;
fn partition(self, f: impl Fn(&T) -> bool + Sync + Send) -> (Vec<T>, Vec<T>);
fn partition3(
        self,
        predicate1: impl Fn(&T) -> bool + Sync + Send,
        predicate2: impl Fn(&T) -> bool + Sync + Send
    ) -> (Vec<T>, Vec<T>, Vec<T>)
    where
        T: Sync
; }
Expand description

This trait is to implement some extension functions for Vec type, which need one generic type, and do not need reference.

Required methods

Implementations on Foreign Types

Executes f on each item produced by the iterator for Vec in parallel.

Examples
use aoko::standard::{functions::ext::*, parallelisms::par_vec_ext::*};

vec![String::from("abc"), String::from("xyz")]
    .for_each(|e| e.echo());

Performs the given f on each element in parallel, and returns the Vec itself afterwards.

Examples
use aoko::standard::{functions::ext::*, parallelisms::par_vec_ext::*};

assert_eq!(vec!["hello", "rust"].on_each(|s| *s.echo()), vec!["hello", "rust"]);

Returns a Vec containing only elements matching the given f predicate in parallel.

Examples
use aoko::standard::parallelisms::par_vec_ext::*;

assert_eq!(vec![1, 2, 3, 4].filter(|i| i % 2 == 0), vec![2, 4]);

Accumulates value starting with initial value, and applying operation f from left to right in parallel.

Returns the specified initial value if the Vec is empty.

Examples
use aoko::standard::parallelisms::par_vec_ext::*;

assert_eq!(vec![1, 2, 3, 4].fold(0, |acc, i| acc + i), 10);

Accumulates value starting with default value, and applying operation f from left to right in parallel.

Returns the default value if the Vec is empty.

Examples
use aoko::standard::parallelisms::par_vec_ext::*;

assert_eq!(vec![1, 2, 3, 4].reduce(|acc, i| acc + i), 10);

Returns the sum of all elements which implement the Add trait in parallel for Vec type.

Examples
use aoko::standard::parallelisms::par_vec_ext::*;

assert_eq!(vec![1, 2, 3, 4].sum(), 10);

Returns the product of all elements which implement the Product trait in parallel for Vec type.

Examples
use aoko::standard::parallelisms::par_vec_ext::*;

assert_eq!(vec![1, 2, 3, 4].product(), 24);

Splits the original Vec into a couple of Vec according to the condition, where first Vec contains elements for which predicate yielded true, while second Vec contains elements for which predicate yielded false.

Examples
use aoko::standard::parallelisms::par_vec_ext::*;

assert_eq!(vec![1, 2, 3, 4].partition(|i| i % 2 != 0), (vec![1, 3], vec![2, 4]));

Splits the original Vec into a triple of Vec according to the condition, where first Vec contains elements for first predicate yielded true, where second Vec contains elements for second predicate yielded true, while third Vec contains elements for which two predicates yielded false.

Examples
use aoko::standard::parallelisms::par_vec_ext::*;

assert_eq!(vec![1, 2, 3].partition3(|i| i < &2, |i| i == &2), (vec![1], vec![2], vec![3]));

Implementors