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 apply for filters

Run a record of closures on the matching fields of a record.

Command Type

built-in

Signature

> record apply {flags} (transforms)

Flags

  • --strict, -s: Error when a transform names a field the input does not have.

Parameters

  • transforms: A record of closures, keyed by the fields they transform.

Input/output types:

inputoutput
recordrecord
tabletable
list<any>list<any>

Examples

Convert the fields of a parsed row.

> {name: ' alice ', age: '42'} | record apply {name: {str trim}, age: {into int}}
╭──────┬───────╮
│ name │ alice │
│ age  │ 42    │
╰──────┴───────╯

Transform a nested field with a nested record of closures.

> {server: {host: localhost, port: '8080'}} | record apply {server: {port: {into int}}}
╭────────┬──────────────────────╮
│        │ ╭──────┬───────────╮ │
│ server │ │ host │ localhost │ │
│        │ │ port │ 8080      │ │
│        │ ╰──────┴───────────╯ │
╰────────┴──────────────────────╯

Transforms for missing fields are skipped.

> {a: 1} | record apply {a: {|x| $x + 1}, b: {|x| $x * 2}}
╭───┬───╮
│ a │ 2 │
╰───┴───╯

Convert a column of every row of a table.

> [{name: a, size: '1'} {name: b, size: '2'}] | record apply {size: {into int}}
╭───┬──────┬──────╮
│ # │ name │ size │
├───┼──────┼──────┤
│ 0 │ a    │    1 │
│ 1 │ b    │    2 │
╰───┴──────┴──────╯

Notes

Each closure runs on the input field with the same key. It receives the field's value as its argument and as $in, and its result replaces the value. A nested record of closures applies to a nested record field in the same way. Fields without a transform pass through unchanged. Transforms for fields the input does not have are skipped, unless --strict is given. The transforms record is checked before any closure runs. Given a list of records, the transforms are applied to each record in turn and the results are streamed.