locrian 0.2.2

A simple embeddable functional programming language.
Documentation
use crate::eval::EvalFn;

pub(crate) static pipe: EvalFn = func!(
    r#"
        use(["array"],
            'reduce($arguments,
                'let({"value": $0, "fn": $1},
                    'call(fn, [value]))))
    "#
);

pub(crate) static do_: EvalFn = func!(
    r#"
        use(["array"],
            'let({"results": map($arguments, 'call($it, []))},
                'last(results)))
    "#
);

#[cfg(test)]
mod tests {
    use crate::{eval::EvalResult, eval_str, stdlib::STDLIB};

    #[test]
    fn test_pipe() {
        assert_eq!(
            eval_str(
                r#"
            use(["array", "num"],
                'pipe(
                    [1, 2, 3],
                    'map($0, 'mul($it, 2)),
                    'add(...$0)))
            "#,
                STDLIB.clone()
            )
            .unwrap(),
            EvalResult::Number(12 as f64)
        )
    }

    #[test]
    fn test_do() {
        assert_eq!(
            eval_str(
                r#"
                do(
                    'array:map([1, 2, 3], 'num:mul($it, 2)),
                    'num:add(3, 5)
                )
                "#,
                STDLIB.clone()
            )
            .unwrap(),
            EvalResult::Number(8 as f64)
        )
    }
}