dimanche 13 mars 2016

How to figure out what protocols the type implements?

Given some type or record, how can I get all the protocols it implements?

Let's say we have the following code:

(defprotocol P1
  (op1 [this]))

(defprotocol P2
  (op2 [this]))

(defrecord R []
  P1
  (op1 [_] 1)
  P2
  (op2 [_] 2))

And what I need is a function that does something like this:

(all-protocols-for-type R) ;; => (P1 P2)

It will be good if there's something backend-agnosting, because I'd like to have a mechanism for both Clojure and ClojureScript.





Aucun commentaire:

Enregistrer un commentaire