From eeb3b38fbac8da8c9628fc232ba7b81a619260bb Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Sun, 16 Jul 2023 08:13:46 -0500 Subject: [PATCH] allow range as a input_output_type on filter (#9707) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Description This PR allows `Type::Range` on the `filter` command so you can do things like this: ```nushell ❯ 9..17 | filter {|el| $el mod 2 != 0} ╭───┬────╮ │ 0 │ 9 │ │ 1 │ 11 │ │ 2 │ 13 │ │ 3 │ 15 │ │ 4 │ 17 │ ╰───┴────╯ ``` # User-Facing Changes # Tests + Formatting # After Submitting --- crates/nu-command/src/filters/filter.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/crates/nu-command/src/filters/filter.rs b/crates/nu-command/src/filters/filter.rs index e092c1f119..fc3b713ffd 100644 --- a/crates/nu-command/src/filters/filter.rs +++ b/crates/nu-command/src/filters/filter.rs @@ -32,6 +32,7 @@ a variable. On the other hand, the "row condition" syntax is not supported."# Type::List(Box::new(Type::Any)), ), (Type::Table(vec![]), Type::Table(vec![])), + (Type::Range, Type::List(Box::new(Type::Any))), ]) .required( "closure", @@ -224,6 +225,14 @@ a variable. On the other hand, the "row condition" syntax is not supported."# span: Span::test_data(), }), }, + Example { + description: "Filter items of a range according to a condition", + example: "9..13 | filter {|el| $el mod 2 != 0}", + result: Some(Value::List { + vals: vec![Value::test_int(9), Value::test_int(11), Value::test_int(13)], + span: Span::test_data(), + }), + }, // TODO: This should work but does not. (Note that `Let` must be present in the working_set in `example_test.rs`). // See https://github.com/nushell/nushell/issues/7034 // Example {