pub trait ArrayIter<N: Numeric>where
Self: Sized + Clone,{
// Required methods
fn for_each<F: FnMut(&N)>(&self, f: F) -> Result<(), ArrayError>;
fn for_each_e<F: FnMut(usize, &N)>(&self, f: F) -> Result<(), ArrayError>;
fn map<F: FnMut(&N) -> N>(&self, f: F) -> Result<Array<N>, ArrayError>;
fn map_e<F: FnMut(usize, &N) -> N>(
&self,
f: F
) -> Result<Array<N>, ArrayError>;
fn filter<F: FnMut(&N) -> bool>(&self, f: F) -> Result<Array<N>, ArrayError>;
fn filter_e<F: FnMut(usize, &N) -> bool>(
&self,
f: F
) -> Result<Array<N>, ArrayError>;
fn filter_map<F: FnMut(&N) -> Option<N>>(
&self,
f: F
) -> Result<Array<N>, ArrayError>;
fn filter_map_e<F: FnMut(usize, &N) -> Option<N>>(
&self,
f: F
) -> Result<Array<N>, ArrayError>;
fn fold<F: FnMut(&N, &N) -> N>(
&self,
init: N,
f: F
) -> Result<N, ArrayError>;
}Expand description
ArrayTrait - Array Iterable functions
Required Methods§
sourcefn for_each_e<F: FnMut(usize, &N)>(&self, f: F) -> Result<(), ArrayError>
fn for_each_e<F: FnMut(usize, &N)>(&self, f: F) -> Result<(), ArrayError>
sourcefn filter_e<F: FnMut(usize, &N) -> bool>(
&self,
f: F
) -> Result<Array<N>, ArrayError>
fn filter_e<F: FnMut(usize, &N) -> bool>( &self, f: F ) -> Result<Array<N>, 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();sourcefn filter_map<F: FnMut(&N) -> Option<N>>(
&self,
f: F
) -> Result<Array<N>, ArrayError>
fn filter_map<F: FnMut(&N) -> Option<N>>( &self, f: F ) -> Result<Array<N>, ArrayError>
Filter and map over 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_map(|item| if item % 2 == 0 { Some(*item) } else { None }).unwrap();sourcefn filter_map_e<F: FnMut(usize, &N) -> Option<N>>(
&self,
f: F
) -> Result<Array<N>, ArrayError>
fn filter_map_e<F: FnMut(usize, &N) -> Option<N>>( &self, f: F ) -> Result<Array<N>, ArrayError>
Filter and map 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_map_e(|idx, item| if item % (idx + 1) as i32 == 0 { Some(*item) } else { None }).unwrap();