Skip to content

ForEach

Name Mandatory Description Default Type
⬅️ Input Sequence/table whose elements or key-value pairs need to be processed. [Any]{Any}
Output ➡️ Outputs the input value, passed through unchanged. [Any]{Any}
Apply No The processing logic (in the form of a shard or sequence of shards) to apply to the input sequence/table. none Shard[Shard]

Processes every element or key-value pair of a sequence/table with the shards specified in the Apply parameter. Note that this shard is able to use the $0 and $1 internal variables, as well as $i for the current index.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
; ForEach on a sequence: processes every element in seq order
[2 4 8 10] | ForEach({
  {Math.Multiply(10) | Log}  ; => 20, 40, 80, 100
  {Math.Multiply(100) | Log} ; => 200, 400, 800, 1000
})

; ForEach on a table: processes every key in alphabetic order
{Name: "Universe" Age: "13.8B Yrs"} | ForEach({
  ; receives each key/value pair as a sequence in alphabetic order of key
  {Slice(0 1 1) | Log}  ; => ["Age"], ["Name"]
  {Slice(1 2 1) | Log}  ; => ["13.8 B Yrs"], ["Universe"]
})

[info] [sample-wire] 20
[info] [sample-wire] 200
[info] [sample-wire] 40
[info] [sample-wire] 400
[info] [sample-wire] 80
[info] [sample-wire] 800
[info] [sample-wire] 100
[info] [sample-wire] 1000
[info] [sample-wire] [Age]
[info] [sample-wire] [13.8B Yrs]
[info] [sample-wire] [Name]
[info] [sample-wire] [Universe]