Skip to content

Instantly share code, notes, and snippets.

@AlexBaranosky
Created November 23, 2012 08:27
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save AlexBaranosky/4134522 to your computer and use it in GitHub Desktop.
Save AlexBaranosky/4134522 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)))))
@viebel
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