Skip to content

Instantly share code, notes, and snippets.

@longfin
Created July 10, 2012 16:31
Show Gist options
  • Save longfin/3084489 to your computer and use it in GitHub Desktop.
Save longfin/3084489 to your computer and use it in GitHub Desktop.
protocol example
(defprotocol IDocumentable
"Representable protocol for mongodb's document name"
(docname [e]))
(defprotocol IEntity
"Protocol of whole entity."
(add! [e])
(edit! [e])
(remove! [e]))
(extend-protocol IDocumentable
java.lang.String
(docname [e]
(lower-case e))
clojure.lang.Symbol
(docname [e]
(docname (str e)))
java.lang.Class
(docname [e]
(let [fullname (.getName e)]
(docname (last (split fullname #"\.")))))
warklet.model.IEntity
(docname [e]
(docname (type e))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment