[][src]Function parsley::proc_utils::make_fold_numeric

pub fn make_fold_numeric<F, T>(init: T, f: F, name: Option<&str>) -> SExp where
    F: Fn(T, Num) -> T + 'static,
    T: Into<SExp> + Clone + 'static, 

Make a variadic procedure that takes a list of numeric arguments and folds the whole list.

Note

The underlying numeric type is f64.

Example

use parsley::prelude::*;
use parsley::proc_utils::*;
use parsley::Num;

let my_adder = |accumulator, current| accumulator + current;
let my_add_proc = make_fold_numeric(Num::from(0), my_adder, None);

assert_eq!(
    Context::base().eval(
        sexp![my_add_proc, 1, 2, 3, 4]
    ).unwrap(),
    SExp::from(10),
);