-
-
Save ghoseb/4134640 to your computer and use it in GitHub Desktop.
doseq-indexed
This file contains hidden or 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
;; 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