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

each while for filters

Run a closure 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:

inputoutput
list<any>list<any>

Examples

Produces a list of each element before the 3, doubled

> [1 2 3 2 1] | each while {|e| if $e < 3 { $e * 2 } }
╭───┬───╮
│ 0 │ 2 │
│ 1 │ 4 │
╰───┴───╯

Output elements until reaching 'stop'

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

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

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