Repository navigation
feat(any/all): Allow using row conditions alongside closures - #18353
Conversation
|
I like this change but I don't entirely understand what we want to deprecate here? |
|
Re @cptpiepmatz: Passing just While this seems like a niche use-case to me since it'd only work on a list of bools, the first examples of both commands do use |
|
I'll look into making it parse as an empty closure instead. That would be cleaner IMO. |
|
@Bahex do we want to merge this PR as is still and then take your changes later on? |
|
I'll try getting it done today, I don't want to go back and forth on command signatures and warnings. Aside from that, it might be best to discuss this with the core team. IIRC row conditions used to be more common and not just constrained to I personally do like this for the record. |
## Description
While parsing row conditions, prioritize parsing possible closures
before anything else.
## User-facing changes (Release notes)
Empty braces (`{}`) as row conditions are now parsed as empty closures
rather than empty records.
```nushell
1..3 | where {}
```
- before:
```
Error: nu::parser::type_mismatch
× Type mismatch.
╭─[repl_entry #1:1:14]
1 │ 1..3 | where {}
· ─┬
· ╰── expected bool, found record
╰────
```
- after:
```
╭────────────╮
│ empty list │
╰────────────╯
```
## Additional notes
- This should help keep #18353 backwards compatible.
|
@Mrfiregem I merged the parser fix. You can rebase on main and then just remove the deprecation related code. |
|
We talked about this today in our meeting and we like it. Gonna merge it after the release |
|
I'd also like to see row-conditions in any command that it makes sense for. |
|
Thanks |
|
|
## Description Based on fdncred's comment in #18353, adds row conditions to every other command using a predicate-like closure. ## User-facing changes (Release notes) Allow `take until`, `take while`, `skip until`, `skip while`, and `chunk-by` to use row condition syntax alongside closures. ## Additional notes Updated examples cover most test cases, but waiting on writing tests depending on if there are any more additions / removals. It looks like the `-i` flag of `take until` and `take while` must be proved to the command before the predicate even it it's given as a closure.
Description
I believe
where's row conditions to be a nice syntax for that command, and always thoughtallandany, being in the same sort of vein aswherewould also benefit from them. As it turns out, it's as simple as changing the syntax shape, so I thought I'd make this PR and let the maintainers decide if they wanted to implement this or not.User-facing changes (Release notes)
anyandallnow accept row conditions just likewhereIn addition to the current closure syntax,
anyandallcan now be given row conditions to make writing filters more streamlined.Just like with
where, you can reference column names directly, and use the$itvariable to construct predicates given to both commands, or continue to use closures for more extensive constructions.Additional notes
In the past, it's been discussed about removing row conditions entirely, but looking at the current state of discussion, it doesn't seem to be going that way right now. If that's still the case, though, I'm fine with this PR being closed.
Currently,{}is still supported, though with a deprecation warning, which required fudging the type signatures a bit.