Skip to content

feat(any/all): Allow using row conditions alongside closures - #18353

Merged
fdncred merged 9 commits into
nushell:mainfrom
Mrfiregem:any-all-row-cond
Jul 14, 2026
Merged

fdncred merged 9 commits into
nushell:mainfrom
Mrfiregem:any-all-row-cond

Conversation

@Mrfiregem

@Mrfiregem Mrfiregem commented Jun 5, 2026 •

Copy link
Copy Markdown
Contributor

Description

I believe where's row conditions to be a nice syntax for that command, and always thought all and any, being in the same sort of vein as where would 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)

any and all now accept row conditions just like where

In addition to the current closure syntax, any and all can now be given row conditions to make writing filters more streamlined.

[9 8 7 6] | enumerate | any item == index * 2

Just like with where, you can reference column names directly, and use the $it variable to construct predicates given to both commands, or continue to use closures for more extensive constructions.

[1sec 1min 1hr] | all ($it | describe) == 'duration'

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.

@cptpiepmatz

cptpiepmatz commented Jun 18, 2026 •

Copy link
Copy Markdown
Member

I like this change but I don't entirely understand what we want to deprecate here?

@Mrfiregem

Mrfiregem commented Jun 19, 2026 •

Copy link
Copy Markdown
Contributor Author

Re @cptpiepmatz: Passing just {} as an argument to a command expecting a row condition is treated as giving it a row condition that evaluates to an empty record instead of a no-op closure, which it was treated as before (Not sure if this is expected, but there are simple workarounds given in the deprecation notice). This throws a type error since the returned record can't be converted to a bool.

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 {}, so I'm playing it safe by special-casing it and warning the user that that syntax won't work in future versions. My method did require me to fudge the type signature a bit for the duration of the deprecation, though, so if you think of a better way, I'll gladly implement that instead.

@Bahex

Bahex commented Jun 19, 2026

Copy link
Copy Markdown
Member

I'll look into making it parse as an empty closure instead. That would be cleaner IMO.

@cptpiepmatz

Copy link
Copy Markdown
Member

@Bahex do we want to merge this PR as is still and then take your changes later on?

@Bahex

Bahex commented Jun 19, 2026

Copy link
Copy Markdown
Member

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 where, and were cut back on due to parsing issues (I think?). We should look through the history of those changes and not make a final decision until there is consensus.

I personally do like this for the record.

Bahex added a commit that referenced this pull request Jun 19, 2026
## 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.
@Bahex

Bahex commented Jun 19, 2026

Copy link
Copy Markdown
Member

@Mrfiregem I merged the parser fix.

You can rebase on main and then just remove the deprecation related code.

@fdncred

fdncred commented Jun 19, 2026 •

Copy link
Copy Markdown
Contributor

@Bahex we removed row conditions because the thinking prior was that it was "too much magic". i personally like row conditions and would use them anywhere that it fits. i can probably find the pr where we removed them.

Here's a couple PRs where we started making changes to this.
#7428
#7365

@cptpiepmatz

Copy link
Copy Markdown
Member

We talked about this today in our meeting and we like it. Gonna merge it after the release

@fdncred

fdncred commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

I'd also like to see row-conditions in any command that it makes sense for.

@fdncred
fdncred merged commit 990e715 into nushell:main Jul 14, 2026
17 checks passed
@fdncred

fdncred commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Thanks

@github-actions github-actions Bot added this to the v0.115.0 milestone Jul 14, 2026
@fdncred fdncred added notes:ready Indicates Ready for Release notes notes:additions Noted in "Additions" section labels Jul 14, 2026
@Mrfiregem
Mrfiregem deleted the any-all-row-cond branch July 15, 2026 13:15
@blindFS

blindFS commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

A side note: I have no idea of how to make tree-sitter-nu support this new syntax. Better to resort to agents for that matter. Otherwise there will be a new discrepancy.

fdncred pushed a commit that referenced this pull request Sep 2, 2026
## 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes:additions Noted in "Additions" section notes:ready Indicates Ready for Release notes status:wait-until-after-nushell-release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants