Skip to content

Instantly share code, notes, and snippets.

@ghoseb
Forked from AlexBaranosky/gist:4134522
Created November 23, 2012 09:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ghoseb/4134640 to your computer and use it in GitHub Desktop.
Save ghoseb/4134640 to your computer and use it in GitHub Desktop.
doseq-indexed
;; 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#)]
~@body
(swap! idx-atom# inc)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment