Trait naan::fold::FoldableIndexed
source · pub trait FoldableIndexed<F, Idx, A>where
F: HKT1<T<A> = Self>,
Self: Foldable<F, A>,
Idx: Clone,{
// Required methods
fn foldl_idx<B, BAB>(self, f: BAB, b: B) -> B
where BAB: F3<B, Idx, A, Ret = B>;
fn foldr_idx<B, ABB>(self, f: ABB, b: B) -> B
where ABB: F3<Idx, A, B, Ret = B>;
fn foldl_idx_ref<'a, B, BAB>(&'a self, f: BAB, b: B) -> B
where BAB: F3<B, Idx, &'a A, Ret = B>,
A: 'a,
Idx: 'a;
fn foldr_idx_ref<'a, B, ABB>(&'a self, f: ABB, b: B) -> B
where ABB: F3<Idx, &'a A, B, Ret = B>,
A: 'a,
Idx: 'a;
}
Expand description
Foldable
for indexed collections
Required Methods§
sourcefn foldl_idx<B, BAB>(self, f: BAB, b: B) -> Bwhere
BAB: F3<B, Idx, A, Ret = B>,
fn foldl_idx<B, BAB>(self, f: BAB, b: B) -> Bwhere BAB: F3<B, Idx, A, Ret = B>,
Fold the data structure from left -> right
sourcefn foldr_idx<B, ABB>(self, f: ABB, b: B) -> Bwhere
ABB: F3<Idx, A, B, Ret = B>,
fn foldr_idx<B, ABB>(self, f: ABB, b: B) -> Bwhere ABB: F3<Idx, A, B, Ret = B>,
Fold the data structure from right -> left
sourcefn foldl_idx_ref<'a, B, BAB>(&'a self, f: BAB, b: B) -> Bwhere
BAB: F3<B, Idx, &'a A, Ret = B>,
A: 'a,
Idx: 'a,
fn foldl_idx_ref<'a, B, BAB>(&'a self, f: BAB, b: B) -> Bwhere BAB: F3<B, Idx, &'a A, Ret = B>, A: 'a, Idx: 'a,
Fold the data structure from left -> right
sourcefn foldr_idx_ref<'a, B, ABB>(&'a self, f: ABB, b: B) -> Bwhere
ABB: F3<Idx, &'a A, B, Ret = B>,
A: 'a,
Idx: 'a,
fn foldr_idx_ref<'a, B, ABB>(&'a self, f: ABB, b: B) -> Bwhere ABB: F3<Idx, &'a A, B, Ret = B>, A: 'a, Idx: 'a,
Fold the data structure from right -> left
Implementations on Foreign Types§
source§impl<A, K> FoldableIndexed<HashMapValues<K>, K, A> for HashMap<K, A>where
K: Eq + Hash + Clone,
impl<A, K> FoldableIndexed<HashMapValues<K>, K, A> for HashMap<K, A>where K: Eq + Hash + Clone,
fn foldl_idx<B, BAB>(self, f: BAB, b: B) -> Bwhere BAB: F3<B, K, A, Ret = B>,
fn foldr_idx<B, ABB>(self, f: ABB, b: B) -> Bwhere ABB: F3<K, A, B, Ret = B>,
fn foldl_idx_ref<'a, B, BAB>(&'a self, f: BAB, b: B) -> Bwhere BAB: F3<B, K, &'a A, Ret = B>, A: 'a,
fn foldr_idx_ref<'a, B, ABB>(&'a self, f: ABB, b: B) -> Bwhere ABB: F3<K, &'a A, B, Ret = B>, A: 'a,
source§impl<A> FoldableIndexed<Vec, usize, A> for Vec<A>
impl<A> FoldableIndexed<Vec, usize, A> for Vec<A>
source§fn foldr_idx<B, ABB>(self, f: ABB, b: B) -> Bwhere
ABB: F3<usize, A, B, Ret = B>,
fn foldr_idx<B, ABB>(self, f: ABB, b: B) -> Bwhere ABB: F3<usize, A, B, Ret = B>,
CHECK: Enumerate yields indexes (not the number of iterations) when going backwards in a double ended iterator
use naan::prelude::*;
vec![0, 1, 2].foldl_idx(|(), ix, val| assert_eq!(ix, val), ());
vec![0, 1, 2].foldr_idx(|ix, val, ()| assert_eq!(ix, val), ());