Trait arr_rs::core::operations::iter::ArrayIterMut
source · pub trait ArrayIterMut<S: ArrayElement, T: ArrayElement>where
Self: Sized + Clone,{
// Required methods
fn map<F: FnMut(&T) -> S>(&self, f: F) -> Result<Array<S>, ArrayError>;
fn map_e<F: FnMut(usize, &T) -> S>(
&self,
f: F
) -> Result<Array<S>, ArrayError>;
fn filter_map<F: FnMut(&T) -> Option<S>>(
&self,
f: F
) -> Result<Array<S>, ArrayError>;
fn filter_map_e<F: FnMut(usize, &T) -> Option<S>>(
&self,
f: F
) -> Result<Array<S>, ArrayError>;
fn fold<F: FnMut(&S, &T) -> S>(
&self,
init: S,
f: F
) -> Result<S, ArrayError>;
fn zip(&self, other: &Array<S>) -> Result<Array<Tuple2<T, S>>, ArrayError>;
}
Expand description
ArrayTrait - Array Iterable functions
Required Methods§
sourcefn filter_map<F: FnMut(&T) -> Option<S>>(
&self,
f: F
) -> Result<Array<S>, ArrayError>
fn filter_map<F: FnMut(&T) -> Option<S>>( &self, f: F ) -> Result<Array<S>, 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, &T) -> Option<S>>(
&self,
f: F
) -> Result<Array<S>, ArrayError>
fn filter_map_e<F: FnMut(usize, &T) -> Option<S>>( &self, f: F ) -> Result<Array<S>, 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();
sourcefn zip(&self, other: &Array<S>) -> Result<Array<Tuple2<T, S>>, ArrayError>
fn zip(&self, other: &Array<S>) -> Result<Array<Tuple2<T, S>>, ArrayError>
‘Zips up’ two iterators into a single iterator of pairs
Arguments
other
- array to zip with
Examples
use arr_rs::prelude::*;
let arr_1: Array<i32> = Array::flat(vec![1, 2]).unwrap();
let arr_2: Array<i32> = Array::flat(vec![5, 6]).unwrap();
assert_eq!(Array::flat(vec![Tuple2(1, 5), Tuple2(2, 6)]), arr_1.zip(&arr_2));