update for filters

Update an existing column to have a new value.

Signature

> update {flags} (field) (replacement value)

Parameters

  • field: the name of the column to update
  • replacement value: the new value to give the cell(s), or a closure to create the value

Input/output types:

input output
list<any> list<any>
record record
table table

Examples

Update a column value

> {'name': 'rsh', 'stars': 5} | update name 'rsh'
╭───────┬─────────╮
│ name  │ rsh │
│ stars │ 5       │
╰───────┴─────────╯

Use in closure form for more involved updating logic

> [[count fruit]; [1 'apple']] | enumerate | update item.count {|e| ($e.item.fruit | str length) + $e.index } | get item
╭───┬───────┬───────╮
│ # │ count │ fruit │
├───┼───────┼───────┤
│ 0 │     5 │ apple │
╰───┴───────┴───────╯

Alter each value in the 'authors' column to use a single string instead of a list

> [[project, authors]; ['rsh', ['Andrés', 'JT', 'Yehuda']]] | update authors {|row| $row.authors | str join ','}
╭───┬─────────┬──────────────────╮
│ # │ project │     authors      │
├───┼─────────┼──────────────────┤
│ 0 │ rsh      │ Andrés,JT,Yehuda │
╰───┴─────────┴──────────────────╯

You can also use a simple command to update 'authors' to a single string

> [[project, authors]; ['rsh', ['Andrés', 'JT', 'Yehuda']]] | update authors {|| str join ','}
╭───┬─────────┬──────────────────╮
│ # │ project │     authors      │
├───┼─────────┼──────────────────┤
│ 0 │ rsh      │ Andrés,JT,Yehuda │
╰───┴─────────┴──────────────────╯

Subcommands:

name type usage
update cells Builtin Update the table cells.