Spec-Zone.ru › Nushell

compact for filters

Creates a table with non-empty rows.

Signature

> compact {flags} ...rest

Flags

  • --empty, -e: Also compact empty items like "", {}, and [].

Parameters

  • ...rest: The columns to compact from the table.

Input/output types:

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

Examples

Filter out all records where 'Hello' is null

> [["Hello" "World"]; [null 3]] | compact Hello
╭────────────╮
│ empty list │
╰────────────╯

Filter out all records where 'World' is null

> [["Hello" "World"]; [null 3]] | compact World
╭───┬───────┬───────╮
│ # │ Hello │ World │
├───┼───────┼───────┤
│ 0 │       │     3 │
╰───┴───────┴───────╯

Filter out all instances of null from a list

> [1, null, 2] | compact
╭───┬───╮
│ 0 │ 1 │
│ 1 │ 2 │
╰───┴───╯

Filter out all instances of null and empty items from a list

> [1, null, 2, "", 3, [], 4, {}, 5] | compact --empty
╭───┬───╮
│ 0 │ 1 │
│ 1 │ 2 │
│ 2 │ 3 │
│ 3 │ 4 │
│ 4 │ 5 │
╰───┴───╯

Filter out all instances of null from a record

> {a: 1, b: null, c: 3} | compact
╭───┬───╮
│ a │ 1 │
│ c │ 3 │
╰───┴───╯

Notes

Can be used to remove null or empty values from lists and records too.

Copyright © 2019–2026 The Nushell Project DevelopersLicensed under the MIT License.
https://www.nushell.sh/commands/docs/compact.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API