record each for filters
Command Type
built-in
Signature
> record each {flags} (closure)
Parameters
closure: The closure that returns the new entry for each field.
Input/output types:
| input | output |
|---|---|
| record | record |
| table | table |
| list<any> | list<any> |
Examples
Uppercase the keys and scale the values in one pass.
> {a: 1, b: 2} | record each {|key, value| {($key | str uppercase): ($value * 10)}}
╭───┬────╮
│ A │ 10 │
│ B │ 20 │
╰───┴────╯Swap keys and values by returning two-element lists.
> {a: x, b: y} | record each {|key, value| [$value $key]}
╭───┬───╮
│ x │ a │
│ y │ b │
╰───┴───╯Drop a field by returning null, and trim the others.
> {user: ' alice ', password: secret} | record each {|key, value| if $key != password { {$key: ($value | str trim)} } }
╭──────┬───────╮
│ user │ alice │
╰──────┴───────╯Lowercase the column names of every row of a table.
> [{Name: a, Size: 1} {Name: b, Size: 2}] | record each {|key, value| {($key | str lowercase): $value}}
╭───┬──────┬──────╮
│ # │ name │ size │
├───┼──────┼──────┤
│ 0 │ a │ 1 │
│ 1 │ b │ 2 │
╰───┴──────┴──────╯Notes
The closure receives each field's key and value as two arguments, like items, and $in is empty. It returns the new entry as a record such as {newkey: newvalue} or as a two-element list [newkey, newvalue], or null to drop the field. Every field of a returned record is added, so one field can become several. Entries are added in order. When two entries share a key, the later value replaces the earlier one in the earlier position, as with into record. Given a list of records, each record is rebuilt on its own and the results are streamed.