Skip to content

Instantly share code, notes, and snippets.

@jmorton
Created January 20, 2017 16:32
Show Gist options
  • Save jmorton/068a56fc41d5e3ed7c8af0619100e8fe to your computer and use it in GitHub Desktop.
Save jmorton/068a56fc41d5e3ed7c8af0619100e8fe to your computer and use it in GitHub Desktop.
(defmulti numberize (fn [n] (type n)))
(defmethod numberize :default [n]
':clojure.spec/invalid)
(defmethod numberize Number [number]
number)
(defmethod numberize String [string]
(let [number-format (java.text.NumberFormat/getInstance)]
(try
(.parse number-format string)
(catch java.text.ParseException ex
:clojure.spec/invalid))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment