diff --git a/crates/nu-command/src/filters/each_while.rs b/crates/nu-command/src/filters/each_while.rs index 468e961d4c..f0459cff29 100644 --- a/crates/nu-command/src/filters/each_while.rs +++ b/crates/nu-command/src/filters/each_while.rs @@ -36,24 +36,42 @@ impl Command for EachWhile { fn examples(&self) -> Vec { let stream_test_1 = vec![ Value::Int { - val: 1, + val: 2, span: Span::test_data(), }, Value::Int { - val: 2, + val: 4, + span: Span::test_data(), + }, + ]; + let stream_test_2 = vec![ + Value::String { + val: "Output: 1".into(), + span: Span::test_data(), + }, + Value::String { + val: "Output: 2".into(), span: Span::test_data(), }, ]; vec![ Example { - example: "[1 2 3] | each while { |it| if $it < 3 { $it } else { null } }", - description: "Multiplies elements in list", + example: "[1 2 3] | each while { |it| if $it < 3 { $it * 2 } else { null } }", + description: "Multiplies elements below three by two", result: Some(Value::List { vals: stream_test_1, span: Span::test_data(), }), }, + Example { + example: r#"[1 2 stop 3 4] | each while { |it| if $it == 'stop' { null } else { $"Output: ($it)" } }"#, + description: "Output elements till reaching 'stop'", + result: Some(Value::List { + vals: stream_test_2, + span: Span::test_data(), + }), + }, Example { example: r#"[1 2 3] | each while -n { |it| if $it.item < 2 { $"value ($it.item) at ($it.index)!"} else { null } }"#, description: "Iterate over each element, print the matching value and its index", @@ -140,6 +158,7 @@ impl Command for EachWhile { Err(_) => None, } }) + .fuse() .into_pipeline_data(ctrlc)), PipelineData::ExternalStream { stdout: None, .. } => Ok(PipelineData::new(call.head)), PipelineData::ExternalStream { @@ -198,6 +217,7 @@ impl Command for EachWhile { Err(_) => None, } }) + .fuse() .into_pipeline_data(ctrlc)), PipelineData::Value(x, ..) => { if let Some(var) = block.signature.get_positional(0) {