mirror of
https://github.com/nushell/nushell.git
synced 2024-11-16 05:23:44 +01:00
Merge pull request #21 from jntrnr/simple_value_iteration
Simple value iteration
This commit is contained in:
commit
76c92fc706
@ -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 New Issue
Block a user