W3cubDocs

/Nushell

each while for filters

Run a block on each row of the input list until a null is found, then create a new list with the results.

Signature

> each while {flags} (closure)

Parameters

  • closure: the closure to run

Input/output types:

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

Examples

Produces a list of each element before the 3, doubled

> [12321] |each while {|e| if$e<3 { $e*2 } }
╭───┬───╮
02
14
╰───┴───╯

Output elements until reaching 'stop'

> [12stop34] |each while {|e| if$e!='stop' { $"Output: ($e)" } }
╭───┬───────────╮
0Output:1
1Output:2
╰───┴───────────╯

Iterate over each element, printing the matching value and its index

> [123] |enumerate|each while {|e| if$e.item<2 { $"value ($e.item) at ($e.index)!"} }
╭───┬───────────────╮
0value1at0!
╰───┴───────────────╯

Tips: Command each while was not included in the official binaries by default, you have to build it with --features=extra flag

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