Skip to content

Instantly share code, notes, and snippets.

@mattdeboard
Created August 4, 2012 08:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattdeboard/3256063 to your computer and use it in GitHub Desktop.
Save mattdeboard/3256063 to your computer and use it in GitHub Desktop.
(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