Skip to content

Instantly share code, notes, and snippets.

@verma
Created October 25, 2016 16:15
Show Gist options
  • Save verma/1d673ce8fcfcde671fed89fa61ef6030 to your computer and use it in GitHub Desktop.
Save verma/1d673ce8fcfcde671fed89fa61ef6030 to your computer and use it in GitHub Desktop.
;; iterate over a single collection
(for [x (range 5)]
(* x 2))
;; iterate over multiple collections
(for [x (range 5)
y (range 5)]
[x y])
;; conditional skip certain values
(for [x (range 5)
:when (even? x)
y (range 5)
:when (odd? y)]
[x y])
;; declare intermediate bindings and evaluate conditions on them
(for [x (range 5)
:let [xd (* 2 x)]
:when (zero? (mod xd 4))
y (range 5)
:when (odd? y)]
[x y xd])
;; conditions using multiple bindings
(for [x (range 5)
y (range 5)
z (range 5)
:when (= 10 (+ x y z))]
[x y z])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment