Created
August 4, 2012 08:43
-
-
Save mattdeboard/3256063 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
(defn proxy-meta | |
"Returns an anonymous class instance, constructed with the file on the path | |
indicated by `infile', annotated with metadata indicating the filename used to | |
construct the instance. Optional `moremeta' is a single map containing any | |
additional metadata to add to the instance." | |
[infile & moremeta] | |
(let [metadata (merge {:filename infile} (first moremeta))] | |
(proxy [PdfReader clojure.lang.IObj] [infile] | |
(withMeta [new-meta] (merge metadata new-meta)) | |
(meta [] metadata)))) | |
(defn with-proxy-meta | |
"Returns a new copy of `obj' with metadata updated as indicated by | |
`metadata'. | |
Usage: `(with-proxy-meta (pdf<- path-to-pdf) {:foo 100})' | |
" | |
[obj metadata] | |
(let [key :filename | |
new-meta (merge (meta obj) metadata)] | |
(proxy-meta (key new-meta) (dissoc new-meta key)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment