Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
;; Example:
;; (doseq-indexed idx [name names]
;; (println (str idx ". " name)
(defmacro doseq-indexed [index-sym [item-sym coll] & body]
`(let [idx-atom# (atom 0)]
(doseq [~item-sym ~coll]
(let [~index-sym (deref idx-atom#)]
(swap! idx-atom# inc)))))
Copy link

AlexBaranosky commented Mar 12, 2016

A lot better:

(defmacro doseq-indexed [index-sym [item-sym coll] & body]
  `(doseq [[~index-sym ~item-sym] (map list (range) ~coll)]

Copy link

viebel commented May 9, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment