collect for core
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:
| input | output |
|---|---|
| any | any |
Examples
Use the second value in the stream.
> [1 2 3] | collect { |x| $x.1 }
2Read 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.
Copyright © 2019–2026 The Nushell Project DevelopersLicensed under the MIT License.
https://www.nushell.sh/commands/docs/collect.html