Spec-Zone.ru › Nushell

par-each for filters

Run a closure on each row of the input list in parallel, creating a new list with the results.

Signature

> par-each {flags} (closure)

Flags

  • --threads, -t {int}: The number of threads to use.
  • --keep-order, -k: Keep sequence of output same as the order of input.

Parameters

  • closure: The closure to run.

Input/output types:

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

Examples

Multiplies each number. Note that the list will become arbitrarily disordered.

> [1 2 3] | par-each {|e| $e * 2 }

Multiplies each number, keeping an original order.

> [1 2 3] | par-each --keep-order {|e| $e * 2 }
╭───┬───╮
│ 0 │ 2 │
│ 1 │ 4 │
│ 2 │ 6 │
╰───┴───╯

Enumerate and sort-by can be used to reconstruct the original order.

> 1..3 | enumerate | par-each {|p| update item ($p.item * 2)} | sort-by item | get item
╭───┬───╮
│ 0 │ 2 │
│ 1 │ 4 │
│ 2 │ 6 │
╰───┴───╯

Output can still be sorted afterward.

> [foo bar baz] | par-each {|e| $e + '!' } | sort
╭───┬──────╮
│ 0 │ bar! │
│ 1 │ baz! │
│ 2 │ foo! │
╰───┴──────╯

Iterate over each element, producing a list showing indexes of any 2s.

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

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

Spec-Zone.ru

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