pub trait ArrayIterMut<S: ArrayElement, T: ArrayElement>{
// 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();
§Errors
may returns ArrayError
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();
§Errors
may returns ArrayError
Sourcefn fold<F: FnMut(&S, &T) -> S>(&self, init: S, f: F) -> Result<S, ArrayError>
fn fold<F: FnMut(&S, &T) -> S>(&self, init: S, f: F) -> Result<S, ArrayError>
Fold elements of array elements
§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.fold(0, |a, b| a + b).unwrap();
arr.fold(1, |a, b| a * b).unwrap();
§Errors
may returns ArrayError
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));
§Errors
may returns ArrayError
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.