Search code examples
javaclassclojureprotocolsextend

Is there an easy reference for Clojure/Java classes and protocols?


I've been experimenting a lot with extending Clojure's protocols to already existing types, but it seems like whenever I have a question like "How would I extend this protocol to all seq-able collections?" or "How would I extend this protocol to all numbers (longs, ratios, integers, floats, etc.)?" I have to do a lot of googling to find the answers, and even then, I'm not always able to find a definitive answer.

Is anyone aware of a handy reference for commonly used clojure.lang.Something, java.lang.SomeJavaClass, etc. classes and protocols? I think it would be beneficial if we had some resource available to help out the Clojurians like myself who have little to no Java experience.

EDIT: To give you an idea of what I'm looking for, in this code:

(defprotocol X
  (do-something [this]))

(extend-protocol X
  ?????? <-- 
  (do-something [this] '(implementation goes here)))

Is there a resource that might have a list of Clojure/Java classes to which it might be useful to extend a protocol?


Solution

  • No direct answer here, but some useful resources:

    • I find Stuart Sierra's class diagram project to be hugely useful for visualizing the class structure of Clojure and Java interfaces it depends on.
    • Chouser has some older static diagrams here
    • If you are creating custom collections via deftype, this scaffolding macro can save you a lot of time