Merge pull request #21 from jntrnr/simple_value_iteration

Simple value iteration
This commit is contained in:
JT 2021-09-06 16:21:13 +12:00 committed by GitHub
commit 76c92fc706
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View File

@ -95,7 +95,22 @@ impl Command for Each {
.into_value_stream(), .into_value_stream(),
span: call.head, span: call.head,
}), }),
_ => Ok(Value::nothing()), Value::RowStream { .. } => panic!("iterating row streams is not yet supported"),
Value::Table { .. } => panic!("table iteration not yet supported"),
x => {
//TODO: we need to watch to make sure this is okay
let engine_state = context.engine_state.borrow();
let block = engine_state.get_block(block_id);
let state = context.enter_scope();
if let Some(var) = block.signature.required_positional.first() {
if let Some(var_id) = &var.var_id {
state.add_var(*var_id, x);
}
}
eval_block(&state, block, Value::nothing())
}
} }
} }
} }

View File

@ -223,3 +223,8 @@ fn range_iteration1() -> TestResult {
fn range_iteration2() -> TestResult { fn range_iteration2() -> TestResult {
run_test("4..1 | each { |y| $y + 100 }", "[104, 103, 102, 101]") run_test("4..1 | each { |y| $y + 100 }", "[104, 103, 102, 101]")
} }
#[test]
fn simple_value_iteration() -> TestResult {
run_test("4 | each { $it + 10 }", "14")
}