Fork me on GitHub
shaun-mahood19:03:08;t=PcAofLxjgU3aQslNzbJnsw We have a lot of code at Pitch, but it’s still pretty easy to get around and fun to work with. Anyone else have large CLJS projects that they still like working with?

😎 4
metal 2

89431 for us, still feels good

πŸ‘ 2
metal 2

πŸŽ‰ 1

In Clojure, if I want to check if a function supports metadata, I can check (instance? clojure.lang.IObj value). What is the corresponding test in Clojurescript?


(defprotocol IMeta
  "Protocol for accessing the metadata of an object."
  (^clj-or-nil -meta [o]
    "Returns the metadata of object o."))

(defprotocol IWithMeta
  "Protocol for adding metadata to an object."
  (^clj -with-meta [o meta]
    "Returns a new object with value of o and metadata meta added to it."))

❀️ 1

Thank you @U2FRKM4TW! How did you find the relative code? Grepping the cljs source? So my check would be (instance? #?(:clj clojure.lang.IObj :cljs IWithMeta) value), right?


Just opened core.cljs in my IDE and looked through all the symbols containing the word meta. The check seems reasonable to me, although not sure why you have an FQN there for IObj but not for IWithMeta.


I didn't test the cljs part yet (it's my first cljc experiment, and I'm not used to open it in both repls), so the cljs side could very well be wrong!


I guess I should add a shadow-cljs config and open the other one too!


I use:

(defn can-meta? [value]
  #?(:clj  (instance? clojure.lang.IObj value)
     :cljs (implements? IWithMeta value)))

πŸ™Œ 1

Ah, right - the predicates should be different, thanks for correcting.


thank you, that's a very useful function!