Skip to content
TurtleKitty edited this page May 11, 2019 · 2 revisions

each

This operator is used to iterate over data structures.

(let (items (range 1 5) total (cell 0))
   (each n items
      (total.set! (+ total.get n)))
   total.get)

; 15

(let (items (apply vector (range 1 5) (:)) total (cell 0))
   (each n items
      (total.set! (+ total.get n)))
   total.get)

; 15

(let (items (: x 1 y 2 z 3 u 4 v 5) total (cell 0))
   (each n items
      (total.set! (+ total.get n.val)))
   total.get)

; 15
Clone this wiki locally