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
type Output
Required Methods
fn foldl(self, folder: Folder, i: Init) -> Self::Output
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
impl<F, Acc> HFoldLeftable<F, Acc, Here> for HNil type Output = Acc;
impl<'a, F, R, H, Acc> HFoldLeftable<HCons<F, HNil>, Acc, Here> for &'a HCons<H, HNil> where
F: FnOnce(Acc, &'a H) -> R, type Output = R;impl<F, FolderHeadR, FolderTail, H, Tail, Acc, Index> HFoldLeftable<HCons<F, FolderTail>, Acc, There<Index>> for HCons<H, Tail> where
Tail: HFoldLeftable<FolderTail, FolderHeadR, Index>,
F: FnOnce(Acc, H) -> FolderHeadR, type Output = <Tail as HFoldLeftable<FolderTail, FolderHeadR, Index>>::Output;impl<'a, F, FolderHeadR, FolderTail, H, Tail, Acc, Index> HFoldLeftable<HCons<F, FolderTail>, Acc, There<Index>> for &'a HCons<H, Tail> where
&'a Tail: HFoldLeftable<FolderTail, FolderHeadR, Index>,
F: FnOnce(Acc, &'a H) -> FolderHeadR, type Output = <&'a Tail as HFoldLeftable<FolderTail, FolderHeadR, Index>>::Output;