record where for filters
Command Type
built-in
Signature
> record where {flags} (condition)
Flags
--keys, -k: Pass only the key, as$itin a row condition, as a closure's argument, and as$in.--values, -v: Pass only the value, as$itin a row condition, as a closure's argument, and as$in.
Parameters
condition: The row condition or closure that decides whether to keep each field.
Input/output types:
| input | output |
|---|---|
| record | record |
| table | table |
| list<any> | list<any> |
Examples
Keep the fields whose value is greater than one.
> {a: 1, b: 2, c: 3} | record where value > 1
╭───┬───╮
│ b │ 2 │
│ c │ 3 │
╰───┴───╯Keep the fields whose key starts with NU_.
> {NU_LOG: debug, HOME: /home/me, NU_THEME: dark} | record where key starts-with NU_
╭──────────┬───────╮
│ NU_LOG │ debug │
│ NU_THEME │ dark │
╰──────────┴───────╯Keep the fields whose value is greater than one, with a closure.
> {a: 1, b: 2, c: 3} | record where {|key, value| $value > 1}
╭───┬───╮
│ b │ 2 │
│ c │ 3 │
╰───┴───╯Drop the fields with empty values.
> {name: app, desc: '', tags: []} | record where --values { is-not-empty }
╭──────┬─────╮
│ name │ app │
╰──────┴─────╯Drop the empty fields of every row of a table.
> [{a: 1, b: ''} {a: '', b: 2}] | record where --values { is-not-empty }
╭───┬────┬────╮
│ # │ a │ b │
├───┼────┼────┤
│ 0 │ 1 │ ❎ │
│ 1 │ ❎ │ 2 │
╰───┴────┴────╯Notes
A row condition sees each field as a {key, value} record, the rows where would see after transpose key value. So record where value > 1 filters on the value and record where key starts-with NU_ on the key. A closure instead receives each field's key and value as two arguments, like items, and $in is empty. With --keys or --values, the condition receives only the key or only the value. A row condition gets it as $it, a closure as its argument, and both as $in, so a closure needs no parameters. Put --keys and --values before the condition, because a row condition takes everything after it. record where keeps the matching fields in their original order. Given a list of records, each record is filtered on its own and the results are streamed.