Created
October 25, 2016 16:15
-
-
Save verma/1d673ce8fcfcde671fed89fa61ef6030 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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