Created
November 8, 2017 16:28
-
-
Save rauhs/a57186d3d37198a963d07df12109e999 to your computer and use it in GitHub Desktop.
This file contains 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
(defmacro with-temp-files | |
"Create a block where `varname` is a temporary `File` containing `content`." | |
[bindings & body] | |
(let [bindings (partition 2 bindings)] | |
`(let ~(into [] | |
(mapcat | |
(fn [[bind-name content]] | |
`[~bind-name (File/createTempFile ~(str bind-name) ".json")])) | |
bindings) | |
~@(mapv | |
(fn [[bind-name content]] | |
`(io/copy ~content ~bind-name)) | |
bindings) | |
(let [rv# (do ~@body)] | |
~@(mapv | |
(fn [[bind-name _]] | |
`(.delete ^File ~bind-name)) | |
bindings) | |
rv#)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment