Trait Foldable

Source
pub trait Foldable<I, F> {
    // Required method
    fn fold(self, init: I, f: F) -> I;
}
Expand description

Foldable heterogenous list

§Example

#![cfg_attr(feature="nightly", feature(unsize, fn_traits, unboxed_closures))]
#[macro_use]
extern crate hetseq;
 
use hetseq::{Foldable, Functor, Queue};
#[cfg(not(feature="nightly"))]
use hetseq::prelude::*;
 
use std::fmt::Display;
lambda![ let Formatter = |arg: Display| -> String { format!("{}", arg) } ];
lambda![
    let Extender = |item, extend: Extend<item>| -> extend {
        extend.extend(::std::iter::once(item));
        extend
    }
];
fn main() {
    let queue = hqueue![1, 2.5];
    let strings = queue.fmap(&Formatter).fold(Vec::new(), &Extender);
    assert_eq!(strings, ["1", "2.5"]);
}

Required Methods§

Source

fn fold(self, init: I, f: F) -> I

fold sequence using Function starting with Init value

Implementors§

Source§

impl<I, F> Foldable<I, F> for List<()>

Source§

impl<I, F> Foldable<I, F> for Queue<()>

Source§

impl<I, F, H, T> Foldable<I, F> for List<(H, T)>
where T: Foldable<I, F>, F: FnMut<(H, I), Output = I>,

Source§

impl<I, F, H, T> Foldable<I, F> for Queue<(H, T)>
where H: for<'a> Foldable<I, &'a mut F>, F: FnMut<(T, I), Output = I>,