Skip to content

Instantly share code, notes, and snippets.

@mnzk
Created March 31, 2012 09:58
Show Gist options
  • Save mnzk/2261412 to your computer and use it in GitHub Desktop.
Save mnzk/2261412 to your computer and use it in GitHub Desktop.
with-open-zipfile.clj
(defmacro with-open-zipfile
[bindings & body]
(let [bindings# (->> bindings
(mapncat 2 (fn [v f]
`(~v (java.util.zip.ZipFile. ~f))))
(into []))]
`(with-open ~bindings# ~@body)))
;; example
(macroexpand-1
`(with-open-zipfile [a "a.zip" b "b.zip"]
(my-logic a b)))
;; result of expand
;;
;;(with-open [a (java.util.zip.ZipFile. "a.zip")
;; b (java.util.zip.ZipFile. "b.zip")]
;; (my-logic a b))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment