Bahex
e0eb29f161
feat(where): Support stored closure (#15697)
# 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 <17417311+Bahex@users.noreply.github.com>
2025-05-13 22:24:45 +03:00
..
2025-05-13 16:49:30 +02:00
2025-04-01 07:15:39 -05:00
2025-01-30 06:50:01 -06:00
2024-08-22 11:38:43 +02:00
2025-05-13 16:49:30 +02:00
2024-02-20 11:08:49 -06:00
2025-05-13 16:49:30 +02:00
2024-10-08 11:01:43 +08:00
2025-04-19 17:02:40 -05:00
2025-05-13 16:49:30 +02:00
2025-05-13 16:49:30 +02:00
2025-01-28 16:03:31 -06:00
2025-03-01 11:30:00 -06:00
2022-11-22 16:58:11 -08:00
2025-03-06 14:21:52 +01:00
2024-05-20 00:35:32 +00:00
2025-02-08 19:57:28 -05:00
2024-05-20 00:35:32 +00:00
2025-05-13 16:49:30 +02:00
2025-02-10 15:32:05 +08:00
2024-05-23 02:05:27 +00:00
2024-05-23 02:05:27 +00:00
2023-04-07 14:09:55 -07:00
2024-07-19 00:21:02 -07:00
2024-06-22 07:41:29 -05:00
2025-05-13 16:49:30 +02:00
2024-11-29 13:37:27 -08:00
2025-05-13 16:49:30 +02:00
2025-03-01 07:47:55 -05:00
2025-05-13 16:49:30 +02:00
2023-09-25 08:00:59 -05:00
2023-09-25 08:00:59 -05:00
2023-04-07 14:09:55 -07:00
2023-10-24 12:48:05 -05:00
2025-05-13 16:49:30 +02:00
2025-04-17 16:57:25 +02:00
2024-06-18 07:19:13 -05:00
2025-04-01 07:17:05 -05:00
2023-11-09 13:51:46 +01:00
2025-05-13 16:49:30 +02:00
2024-10-11 06:43:12 -05:00
2025-02-06 06:56:30 -06:00
2023-04-07 14:09:55 -07:00
2025-05-13 16:49:30 +02:00
2024-05-04 00:53:15 +00:00
2024-04-10 06:27:46 +08:00
2025-05-13 16:49:30 +02:00
2023-05-17 18:55:26 -05:00
2025-05-09 09:38:24 +08:00
2025-05-13 16:49:30 +02:00
2024-05-20 00:35:32 +00:00
2023-11-29 23:21:34 +01:00
2023-09-13 06:35:01 +12:00
2025-01-22 22:24:51 -08:00
2025-01-14 11:44:31 -06:00
2025-01-04 16:41:03 -05:00
2025-04-23 10:47:48 -05:00
2024-04-26 06:33:00 -05:00
2025-01-08 23:09:47 +01:00
2025-05-13 16:49:30 +02:00
2024-08-22 12:02:08 +02:00
2023-11-29 23:21:34 +01:00
2024-03-08 02:18:26 -05:00
2025-05-13 16:49:30 +02:00
2024-09-25 07:48:16 -05:00
2024-04-10 06:27:46 +08:00
2025-05-13 16:49:30 +02:00
2025-05-13 16:49:30 +02:00
2025-02-11 11:33:48 +01:00
2024-02-27 15:05:26 +00:00
2025-04-26 23:24:35 +08:00
2025-05-13 16:49:30 +02:00
2024-05-20 00:35:32 +00:00
2024-11-04 03:39:24 +00:00
2025-05-13 16:49:30 +02:00
2023-08-09 14:12:58 +02:00
2023-09-13 06:35:01 +12:00
2025-05-13 16:49:30 +02:00
2025-03-04 05:34:34 -06:00
2024-12-18 06:36:04 -06:00
2023-11-29 23:21:34 +01:00
2024-08-03 10:09:13 +02:00
2025-04-19 17:02:40 -05:00
2025-05-13 16:49:30 +02:00
2025-02-22 11:42:44 -05:00
2025-05-13 16:49:30 +02:00
2023-07-21 17:32:37 +02:00
2025-05-13 16:49:30 +02:00
2024-05-04 00:53:15 +00:00
2024-08-12 17:29:25 +08:00
2025-05-13 16:49:30 +02:00
2025-05-13 16:49:30 +02:00
2025-05-13 16:49:30 +02:00
2023-11-29 23:21:34 +01:00
2024-10-18 03:05:58 +00:00
2023-07-17 18:43:51 +02:00
2025-05-13 16:49:30 +02:00
2023-07-21 17:32:37 +02:00
2025-05-13 16:49:30 +02:00
2025-01-16 06:10:28 +08:00
2025-05-13 16:49:30 +02:00
2025-05-10 11:28:18 +03:00
2023-04-28 13:25:44 +02:00
2025-05-13 16:49:30 +02:00
2025-05-13 16:49:30 +02:00
2023-04-28 13:25:44 +02:00
2025-01-30 06:50:01 -06:00
2024-03-20 22:14:31 +01:00
2024-10-09 19:18:16 -07:00
2025-05-13 16:49:30 +02:00
2024-09-12 07:16:33 -05:00
2024-05-04 00:53:15 +00:00
2025-02-07 06:56:07 -05:00
2025-01-26 07:20:39 -06:00
2025-05-13 16:49:30 +02:00
2024-09-01 19:03:46 +02:00
2023-11-21 20:48:39 -06:00
2024-11-05 09:33:54 +01:00
2025-02-20 23:34:26 -05:00
2025-05-13 16:49:30 +02:00
2025-05-13 16:49:30 +02:00
2025-05-13 16:49:30 +02:00
2024-10-11 14:13:42 +02:00
2024-03-25 16:51:50 -05:00
2023-11-29 23:21:34 +01:00
2025-05-13 16:49:30 +02:00
2024-05-03 08:36:10 +08:00
2025-05-13 16:49:30 +02:00
2025-05-13 16:49:30 +02:00
2025-05-13 16:49:30 +02:00
2025-05-13 22:24:45 +03:00
2023-07-20 19:10:53 -05:00
2023-09-13 06:35:01 +12:00
2025-05-13 16:49:30 +02:00
2024-04-16 19:08:58 +08:00
2023-11-29 23:21:34 +01:00
2024-05-04 00:53:15 +00:00