Trait aoko::standard::parallelisms::par_vec_ext::StdVecExt2 [−][src]
pub trait StdVecExt2<'a, T, R> where
T: 'a, {
fn map(&'a self, f: impl Fn(&'a T) -> R + Sync + Send) -> Vec<R>;
fn filter_map(
&'a self,
f: impl Fn(&'a T) -> Option<R> + Sync + Send
) -> Vec<R>;
}
Expand description
This trait is to implement some extension functions for Vec
type,
which need two generic types and reference.
Required methods
Implementations on Foreign Types
Returns a Vec
containing the results of applying the given f
function
to each element in the original Vec
.
Examples
use aoko::standard::parallelisms::par_vec_ext::*;
assert_eq!(vec![1, 2, 3].map(|i| i + 1), vec![2, 3, 4]);
A combined map and filter. Filtering is handled via Option
instead of Boolean
such that the output type R
can be different than the input type T
.
Examples
use aoko::standard::parallelisms::par_vec_ext::*;
let v = vec!["apple", "1", "banana", "2"]
.filter_map(|s| s.parse::<u8>().ok());
assert_eq!(v, vec![1, 2]);