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§

source

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

source

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

source

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

source

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,

source§

fn foldl_idx<B, BAB>(self, f: BAB, b: B) -> Bwhere BAB: F3<B, K, A, Ret = B>,

source§

fn foldr_idx<B, ABB>(self, f: ABB, b: B) -> Bwhere ABB: F3<K, A, B, Ret = B>,

source§

fn foldl_idx_ref<'a, B, BAB>(&'a self, f: BAB, b: B) -> Bwhere BAB: F3<B, K, &'a A, Ret = B>, A: 'a,

source§

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>

source§

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

fn foldl_idx<B, BAB>(self, f: BAB, b: B) -> Bwhere BAB: F3<B, usize, A, Ret = B>,

source§

fn foldl_idx_ref<'a, B, BAB>(&'a self, f: BAB, b: B) -> Bwhere BAB: F3<B, usize, &'a A, Ret = B>, A: 'a,

source§

fn foldr_idx_ref<'a, B, ABB>(&'a self, f: ABB, b: B) -> Bwhere ABB: F3<usize, &'a A, B, Ret = B>, A: 'a,

source§

impl<A, K> FoldableIndexed<BTreeMapValues<K>, K, A> for BTreeMap<K, A>where K: Ord + Clone,

source§

fn foldl_idx<B, BAB>(self, f: BAB, b: B) -> Bwhere BAB: F3<B, K, A, Ret = B>,

source§

fn foldr_idx<B, ABB>(self, f: ABB, b: B) -> Bwhere ABB: F3<K, A, B, Ret = B>,

source§

fn foldl_idx_ref<'a, B, BAB>(&'a self, f: BAB, b: B) -> Bwhere BAB: F3<B, K, &'a A, Ret = B>, A: 'a,

source§

fn foldr_idx_ref<'a, B, ABB>(&'a self, f: ABB, b: B) -> Bwhere ABB: F3<K, &'a A, B, Ret = B>, A: 'a,

Implementors§