Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.))
like image 613
yazz.com Avatar asked Nov 20 '25 10:11

yazz.com


2 Answers

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

(= (type (->Html)) Html) ; true
(= (type (->Html)) Tree) ; false

(= (type (->Tree)) Html) ; false
(= (type (->Tree)) Tree) ; true
like image 80
fgui Avatar answered Nov 23 '25 05:11

fgui


The best, host-independent way to do it is:

(instance? Html a)

This will work for any type.

like image 33
Outrovurt Avatar answered Nov 23 '25 07:11

Outrovurt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!