I am using Clojure spec to conform (coerce) a 1 or 2 value of a number type or string into a 1, 2 or :clojure.spec/invalid. (require [[clojure.spec :as s]          [clojure.core.match :as m]])(defn parse-number [n]  Parses a string or number in a safe way.  (m/match [n]    [_ :guard number?] n    [_] (Integer/parseInt (re-find #\A\d+ n))))(defn one-or-two? [n]  (try    (let [parsed-n (parse-number n)]      (m/match [parsed-n]        [1] 1        [2] 2        [_] :clojure.spec/invalid))    (catch Exception _      :clojure.spec/invalid)))(s/def ::one-or-two (s/conformer one-or-two?))Now we can conform and validate values like this:(s/valid? ::one-or-two 1))   ; => true(s/valid? ::one-or-two 2)    ; => true(s/valid? ::one-or-two 3)    ; => false(s/conform ::one-or-two 1) ; => 1(s/conform ::one-or-two 2) ; => 2(s/conform ::one-or-two :2)   ; => :clojure.spec/invalidI have a feeling that the parse-number and one-or-two method can be combined into one, but I do not see how. Can it be done, and if so how?
Pattern match on type in Clojure spec conformer
clojure