mirror of
https://github.com/nushell/nushell
synced 2024-12-30 15:03:25 +00:00
add simple value iteration
This commit is contained in:
parent
96b0edf9b0
commit
3b99ce71a0
2 changed files with 21 additions and 1 deletions
|
@ -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())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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")
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue