Trait frunk_core::hlist::HFoldLeftable [] [src]

pub trait HFoldLeftable<Folder, Init, Index> {
    type Output;
    fn foldl(self, folder: Folder, i: Init) -> Self::Output;
}

Left fold for a given data structure

Associated Types

Required Methods

foldl over a data structure

Examples

let nil = HNil;

assert_eq!(nil.foldl(HNil, 0), 0);

let h = hlist![1, false, 42f32];

let folded = h.as_ref().foldl(
    hlist![
        |acc, &i| i + acc,
        |acc, b: &bool| if !b && acc > 42 { 9000f32 } else { 0f32 },
        |acc, &f| f + acc
    ],
    1
);

assert_eq!(42f32, folded);

// There is also a value-consuming version that passes values to your folding
// functions instead of just references:

let folded2 = h.foldl(
    hlist![
        |acc, i| i + acc,
        |acc, b: bool| if !b && acc > 42 { 9000f32 } else { 0f32 },
        |acc, f| f + acc
    ],
    8918
);

assert_eq!(9042f32, folded2)Run

Implementors