Add currying support.

This commit is contained in:
Stephen Chung
2020-07-22 23:12:09 +08:00
parent e103c8e66c
commit 6d551f1596
10 changed files with 168 additions and 38 deletions

View File

@@ -78,3 +78,35 @@ fn test_fn_ptr() -> Result<(), Box<EvalAltResult>> {
Ok(())
}
#[test]
fn test_fn_ptr_curry() -> Result<(), Box<EvalAltResult>> {
let mut engine = Engine::new();
engine.register_fn("foo", |x: &mut INT, y: INT| *x + y);
#[cfg(not(feature = "no_object"))]
assert_eq!(
engine.eval::<INT>(
r#"
let f = Fn("foo");
let f2 = f.curry(40);
f2.call(2)
"#
)?,
42
);
assert_eq!(
engine.eval::<INT>(
r#"
let f = Fn("foo");
let f2 = curry(f, 40);
call(f2, 2)
"#
)?,
42
);
Ok(())
}