for when

less than 1 minute read

Code

;; for_when.clj

(for [x [:a :b] y (range 5) :when (odd? y)]
  [x y])

(for [x [:a :b] y '(1 3)]
  [x y])

(let [odd-y (filter odd? (range 5))]
  (for [x [:a :b] y odd-y]
    [x y]))

(for [x [:a :b :c] y '(1 3)]
  [x y])

(for [x (range 1 7) y (range 1 7)]
  [x y])

(def die-roll (for [x (range 1 7) y (range 1 7)]
                [x y]))

(map #(apply + %) die-roll)

(frequencies (map #(apply + %) die-roll))

(count (map #(apply + %) die-roll))

Updated: