Skip to content

Instantly share code, notes, and snippets.

@verma verma/for.clj
Created Oct 25, 2016

Embed
What would you like to do?
;; 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
You can’t perform that action at this time.