Skip to content

ForEach

Name - Description Default Type
<input> Sequence/table whose elements or key-value pairs need to be processed. [Any]{Any}
<output> The output from processing the sequence/table elements or key-value pairs. [Any]{Any}
Apply 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 a given shard or sequence of shards.

Examples

1
2
3
4
5
6
7
8
9
;; 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
  ))
[info] [shards/General/ForEach/1.edn] 20
[info] [shards/General/ForEach/1.edn] 200
[info] [shards/General/ForEach/1.edn] 40
[info] [shards/General/ForEach/1.edn] 400
[info] [shards/General/ForEach/1.edn] 80
[info] [shards/General/ForEach/1.edn] 800
[info] [shards/General/ForEach/1.edn] 100
[info] [shards/General/ForEach/1.edn] 1000

 

1
2
3
4
5
6
7
8
9
;; 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) ;; seq => every element starting from 0 till 0 => key of that pair
     (Log))  ;; => ["Age"], ["Name"]
  (| (Slice 1 2 1) ;; seq => every element starting from 1 till 1 => value of that pair
     (Log))  ;; => ["13.8 B Yrs"], ["Universe"]
  ))
[info] [shards/General/ForEach/2.edn] [Age]
[info] [shards/General/ForEach/2.edn] [13.8B Yrs]
[info] [shards/General/ForEach/2.edn] [Name]
[info] [shards/General/ForEach/2.edn] [Universe]