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

collect for filters

Collect a stream into a value.

Signature

> collect {flags} (closure)

Flags

  • --keep-env: let the closure affect environment variables

Parameters

  • closure: The closure to run once the stream is collected.

Input/output types:

inputoutput
anyany

Examples

Use the second value in the stream

> [1 2 3] | collect { |x| $x.1 }
2

Read and write to the same file

> open file.txt | collect | save -f file.txt

Notes

If provided, run a closure with the collected value as input.

The entire stream will be collected into one value in memory, so if the stream is particularly large, this can cause high memory usage.