Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save puredanger/4ca8fd95bcdee0601f09410b4b2f85c2 to your computer and use it in GitHub Desktop.
Save puredanger/4ca8fd95bcdee0601f09410b4b2f85c2 to your computer and use it in GitHub Desktop.
Staged spec validation
;; for the use case where same key is transformed through stage
(s/def :st1/a int?)
(s/def :st2/a string?)
(defn validate-map [stage m]
(every? (fn [[k v]] (s/valid? (keyword stage (name k)) v)) m))
(validate-map "st1" {:a 100}) ;; true
(validate-map "st2" {:a "abc"}) ;; true
(validate-map "st1" {:a "abc"}) ;; false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment