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§

source

fn map<F: FnMut(&T) -> S>(&self, f: F) -> Result<Array<S>, ArrayError>

Map over 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.map(|item| item * 2).unwrap();
source

fn map_e<F: FnMut(usize, &T) -> S>(&self, f: F) -> Result<Array<S>, ArrayError>

Map over enumerated 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.map_e(|idx, item| item * idx as i32).unwrap();
source

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();
source

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();
source

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();
source

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));

Implementors§