user3639782
user3639782

Reputation: 517

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

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

Upvotes: 0

Views: 299

Answers (1)

Nick
Nick

Reputation: 1718

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))

Upvotes: 3

Related Questions