pub trait ArrayIter<T: ArrayElement>where
Self: Sized + Clone,{
// Required methods
fn for_each<F: FnMut(&T)>(&self, f: F) -> Result<(), ArrayError>;
fn for_each_e<F: FnMut(usize, &T)>(&self, f: F) -> Result<(), ArrayError>;
fn filter<F: FnMut(&T) -> bool>(&self, f: F) -> Result<Array<T>, ArrayError>;
fn filter_e<F: FnMut(usize, &T) -> bool>(
&self,
f: F
) -> Result<Array<T>, ArrayError>;
}
Expand description
ArrayTrait - Array Iterable functions
Required Methods§
sourcefn for_each_e<F: FnMut(usize, &T)>(&self, f: F) -> Result<(), ArrayError>
fn for_each_e<F: FnMut(usize, &T)>(&self, f: F) -> Result<(), ArrayError>
sourcefn filter_e<F: FnMut(usize, &T) -> bool>(
&self,
f: F
) -> Result<Array<T>, ArrayError>
fn filter_e<F: FnMut(usize, &T) -> bool>( &self, f: F ) -> Result<Array<T>, ArrayError>
Filter over enumerated array elements Returns a flat filtered array
Arguments
f
- function to be called on each array element
Examples
use arr_rs::prelude::*;
let arr: Array<i32> = Array::new(vec![1, 2, 3, 4, 5, 6, 7, 8], vec![2, 4]).unwrap();
arr.filter_e(|idx, item| item % (idx + 1) as i32 == 0).unwrap();