FEATURE: Allow more expressions in the functional builtins.

This commit is contained in:
Jeremy Wall 2019-01-31 16:38:53 -06:00
parent 3619153218
commit 46ba32f038
2 changed files with 23 additions and 4 deletions

View File

@ -143,4 +143,23 @@ assert {
assert { assert {
ok = reduce((char_iter), [], "foo") == ["f", "o", "o"], ok = reduce((char_iter), [], "foo") == ["f", "o", "o"],
desc = "We can use arbitrary expressions to refer to the macro.", desc = "We can use arbitrary expressions to refer to the macro.",
};
let tpl_with_list = {
list = [1, 2, 3],
};
assert {
ok = reduce(func(acc, s) => acc + [s + 1], [], tpl_with_list.list) == [2, 3, 4],
desc = "We can use full expressions for any of the arguments to reduce",
};
assert {
ok = map(func(item) => item + 1, tpl_with_list.list) == [2, 3, 4],
desc = "We can use full expressions for any of the arguments to map",
};
assert {
ok = filter(func(item) => item != 1, tpl_with_list.list) == [2, 3],
desc = "We can use full expressions for any of the arguments to map",
}; };

View File

@ -577,9 +577,9 @@ make_fn!(
_ => must!(punct!("(")), _ => must!(punct!("(")),
func => must!(expression), func => must!(expression),
_ => must!(punct!(",")), _ => must!(punct!(",")),
acc => must!(trace_parse!(non_op_expression)), acc => must!(trace_parse!(expression)),
_ => must!(punct!(",")), _ => must!(punct!(",")),
tgt => must!(trace_parse!(non_op_expression)), tgt => must!(trace_parse!(expression)),
_ => must!(punct!(")")), _ => must!(punct!(")")),
(Expression::FuncOp(FuncOpDef::Reduce(ReduceOpDef{ (Expression::FuncOp(FuncOpDef::Reduce(ReduceOpDef{
func: Box::new(func), func: Box::new(func),
@ -598,7 +598,7 @@ make_fn!(
_ => must!(punct!("(")), _ => must!(punct!("(")),
func => must!(expression), func => must!(expression),
_ => must!(punct!(",")), _ => must!(punct!(",")),
list => must!(trace_parse!(non_op_expression)), list => must!(trace_parse!(expression)),
_ => must!(punct!(")")), _ => must!(punct!(")")),
(Expression::FuncOp(FuncOpDef::Map(MapFilterOpDef{ (Expression::FuncOp(FuncOpDef::Map(MapFilterOpDef{
func: Box::new(func), func: Box::new(func),
@ -616,7 +616,7 @@ make_fn!(
_ => must!(punct!("(")), _ => must!(punct!("(")),
func => must!(expression), func => must!(expression),
_ => must!(punct!(",")), _ => must!(punct!(",")),
list => must!(trace_parse!(non_op_expression)), list => must!(trace_parse!(expression)),
_ => must!(punct!(")")), _ => must!(punct!(")")),
(Expression::FuncOp(FuncOpDef::Filter(MapFilterOpDef{ (Expression::FuncOp(FuncOpDef::Filter(MapFilterOpDef{
func: Box::new(func), func: Box::new(func),