Nushell
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
  • 한국어
GitHub
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
  • 한국어
GitHub
  • Categories

    • Bits
    • Bytes
    • Chart
    • Conversions
    • Core
    • Database
    • Dataframe
    • Dataframe Or Lazyframe
    • Date
    • Debug
    • Default
    • Env
    • Experimental
    • Expression
    • Filesystem
    • Filters
    • Formats
    • Generators
    • Hash
    • History
    • Lazyframe
    • Math
    • Misc
    • Network
    • Path
    • Platform
    • Plugin
    • Prompt
    • Random
    • Removed
    • Shells
    • Strings
    • System
    • Viewers

record each for filters

Build a new record from the entries a closure returns for each field of a record.

Command Type

built-in

Signature

> record each {flags} (closure)

Parameters

  • closure: The closure that returns the new entry for each field.

Input/output types:

inputoutput
recordrecord
tabletable
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.