-
-
Save jaen/d0fbc37c03933bc286c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(let [make-coercer (fn [schema coercion-matcher] | |
(spec/run-checker | |
(fn [s params] | |
(let [checker (spec/checker (s/spec s) params)] | |
(if-let [coercer (coercion-matcher s)] | |
(fn [x] | |
(macros/try-catchall | |
(let [check-result (checker x)] | |
(if (utils/error? check-result) | |
check-result | |
(coercer check-result))) | |
(catch t (macros/validation-error s x t)))) | |
checker))) | |
true | |
schema)) | |
schema {:date DateTime} | |
value {:date (time/now)} | |
coercion-matcher {DateTime (fn [date-time] | |
(let [unix-timestamp (time-coerce/to-long date-time)] | |
(* unix-timestamp DATE-TIME-CONVERSION-FACTOR)))} | |
coercer (make-coercer schema coercion-matcher)] | |
(coercer value)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment