update cells for filters
Update the table cells.
Command Type
built-in
Signature
> update cells {flags} (closure)
Flags
--columns, -c {list<any>}: List of columns to update.--recursive, -r: Descend into nested records and lists, running the closure on every leaf value.
Parameters
closure: The closure to run an update for each cell.
Input/output types:
| input | output |
|---|---|
| table | table |
| record | record |
Examples
Update the zero value cells to empty strings.
> [
["2021-04-16", "2021-06-10", "2021-09-18", "2021-10-15", "2021-11-16", "2021-11-17", "2021-11-18"];
[ 37, 0, 0, 0, 37, 0, 0]
] | update cells { |value|
if $value == 0 {
""
} else {
$value
}
}
╭─────┬──────────────┬──────────────┬──────────────┬──────────────┬──────────────┬─────────────┬─────────────╮
│ # │ 2021-04-16 │ 2021-06-10 │ 2021-09-18 │ 2021-10-15 │ 2021-11-16 │ 2021-11-17 │ 2021-11-18 │
├─────┼──────────────┼──────────────┼──────────────┼──────────────┼──────────────┼─────────────┼─────────────┤
│ 0 │ 37 │ │ │ │ 37 │ │ │
╰─────┴──────────────┴──────────────┴──────────────┴──────────────┴──────────────┴─────────────┴─────────────╯Update the zero value cells to empty strings in 2 last columns.
> [
["2021-04-16", "2021-06-10", "2021-09-18", "2021-10-15", "2021-11-16", "2021-11-17", "2021-11-18"];
[ 37, 0, 0, 0, 37, 0, 0]
] | update cells -c ["2021-11-18", "2021-11-17"] { |value|
if $value == 0 {
""
} else {
$value
}
}
╭─────┬──────────────┬──────────────┬──────────────┬──────────────┬──────────────┬─────────────┬─────────────╮
│ # │ 2021-04-16 │ 2021-06-10 │ 2021-09-18 │ 2021-10-15 │ 2021-11-16 │ 2021-11-17 │ 2021-11-18 │
├─────┼──────────────┼──────────────┼──────────────┼──────────────┼──────────────┼─────────────┼─────────────┤
│ 0 │ 37 │ 0 │ 0 │ 0 │ 37 │ │ │
╰─────┴──────────────┴──────────────┴──────────────┴──────────────┴──────────────┴─────────────┴─────────────╯Update each value in a record.
> {a: 1, b: 2, c: 3} | update cells { $in + 10 }
╭───┬────╮
│ a │ 11 │
│ b │ 12 │
│ c │ 13 │
╰───┴────╯Update every leaf value in a nested record.
> {a: 1, b: {c: 2, d: [3, 4]}} | update cells --recursive { $in * 10 }
╭───┬────────────────────╮
│ a │ 10 │
│ │ ╭───┬────────────╮ │
│ b │ │ c │ 20 │ │
│ │ │ │ ╭───┬────╮ │ │
│ │ │ d │ │ 0 │ 30 │ │ │
│ │ │ │ │ 1 │ 40 │ │ │
│ │ │ │ ╰───┴────╯ │ │
│ │ ╰───┴────────────╯ │
╰───┴────────────────────╯Notes
By default the closure runs once per cell, so a cell holding a record or list is passed to the closure whole. With --recursive, nested records and lists are descended into instead and the closure runs on each leaf value inside them.