Search code examples
clojurescript

How do I get the type of a record in Clojurescript?


I have two records in Clojurescript defined as follows:

(defrecord Html [])
(defrecord Tree [])

I need to find out the type of the item which can be defined as either of these records, how can I do this?

(def a (Html.))

Solution

  • (defrecord Html [])
    (defrecord Tree [])
    
    (= (type (->Html)) Html) ; true
    (= (type (->Html)) Tree) ; false
    
    (= (type (->Tree)) Html) ; false
    (= (type (->Tree)) Tree) ; true