Spec-Zone.ru › Nushell

take while for filters

Take elements of the input while a predicate is true.

Signature

> take while {flags} (predicate)

Parameters

  • predicate: The predicate that element(s) must match.

Input/output types:

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

Examples

Take while the element is negative.

> [-1 -2 9 1] | take while {|x| $x < 0 }
╭───┬────╮
│ 0 │ -1 │
│ 1 │ -2 │
╰───┴────╯

Take while the element is negative using stored condition.

> let cond = {|x| $x < 0 }; [-1 -2 9 1] | take while $cond
╭───┬────╮
│ 0 │ -1 │
│ 1 │ -2 │
╰───┴────╯

Take while the field value is negative.

> [{a: -1} {a: -2} {a: 9} {a: 1}] | take while {|x| $x.a < 0 }
╭───┬────╮
│ # │ a  │
├───┼────┤
│ 0 │ -1 │
│ 1 │ -2 │
╰───┴────╯

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

Spec-Zone.ru

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