Repository navigation
allow where to work with variables - #5955
Conversation
|
The reedline release process causes |
|
@sholderbach - I would prefer to implement a breaking change. The issue right now is that the different filters are not standardised, some allow for blocks (and hence use $in) while others ask for RowConditions (and hence use $it, and can just use ‘name’ instead of ‘$in.name’). We could standardise it to one or the other, but given the rest of nushell uses $in over $it, I would prefer all filters requiring Blocks instead of RowConditions. However, this will likely be a very large breaking change. |
|
I agree, that it would be best to eliminate the |
|
Looks good. Excited to play with this but will wait until after the release sometime today. Thanks! |
|
Maybe we can push this first to deal with the immediate issue, but I do think in the long-term it will be better to standardise the filters. That's probably way beyond my ability, though. |
|
I agree that I'd like to be more standardized in our filtering. It seems that standardization is a bigger topic than can be resolved here. Let's discuss in discord more to figure out a way forward. I've tested this PR and the old way still works with Let's give it a try and see who we like this. |
# Description - `where` used to be able to filter using stored closures at some point using a flag. > #5955 - This was later removed and `filter` command added to cover the use case. > #7365 This PR once again allows using `where` with closures stored in variables. ```nushell let cond = { $in mod 2 == 0 } 1..10 | where $cond # => ╭───┬────╮ # => │ 0 │ 2 │ # => │ 1 │ 4 │ # => │ 2 │ 6 │ # => │ 3 │ 8 │ # => │ 4 │ 10 │ # => ╰───┴────╯ let nested = {cond: { $in mod 2 == 0 }} 1..10 | where $nested.cond # => ╭───┬────╮ # => │ 0 │ 2 │ # => │ 1 │ 4 │ # => │ 2 │ 6 │ # => │ 3 │ 8 │ # => │ 4 │ 10 │ # => ╰───┴────╯ ``` This does not interfere with using `$it` or one of its fields as the condition. ```nushell [[name state]; [foo true] [bar false] [baz true] [quox false]] | where $it.state # => ╭───┬──────┬───────╮ # => │ # │ name │ state │ # => ├───┼──────┼───────┤ # => │ 0 │ foo │ true │ # => │ 1 │ baz │ true │ # => ╰───┴──────┴───────╯ ``` This change obsoletes `filter`, deprecate it in the future? # User-Facing Changes # Tests + Formatting Added examples and tests. - 🟢 toolkit fmt - 🟢 toolkit clippy - 🟢 toolkit test - 🟢 toolkit test stdlib # After Submitting --------- Co-authored-by: Bahex <[email protected]>
Description
Fixes #5547. Adds an extra
named, so the change is non-breaking.Tests
Make sure you've done the following:
Make sure you've run and fixed any issues with these commands:
cargo fmt --all -- --checkto check standard code formatting (cargo fmt --allapplies these changes)cargo clippy --workspace --features=extra -- -D warnings -D clippy::unwrap_used -A clippy::needless_collectto check that you're using the standard code stylecargo test --workspace --features=extrato check that all the tests pass