matching data type in clojure with core.match/match instead of multimethod

306 views Asked by At

Ho can I have this type matching work. (I am using clojure.core.match/match). Or is multimethod the only way to go.

(let [x "1.2"]
  (match [(read-string x)]
         [^java.lang.Long l] :long
         [^java.lang.Double d] :double
         :else :string))

>> :long

Thanks

1

There are 1 answers

0
Nick On BEST ANSWER

you can do it with a normal condp

(let [x "1.2"]
  (condp = (type (read-string x))
    java.lang.Long :long
    java.lang.Double :double
    :string))