Created
June 8, 2017 02:39
-
-
Save bhb/c0009583ead29e1b0fef80581481cab9 to your computer and use it in GitHub Desktop.
Using `cat` and `keys` within an `or`
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
;; If you "or" between a `keys` and a `cat` spec, you get different types | |
;; of vals in the `explain-data` and it's not clear to me how to work out the original data | |
(s/def ::some-key) | |
(s/def ::or-spec | |
(s/or | |
:map (s/keys :req [::some-key]) | |
:seq (s/cat :i1 int? :i2 int?))) | |
(s/explain-data ::or-spec {:foo :bar}) | |
;; the above yields | |
#:cljs.spec{:problems | |
({:path [:map], | |
:pred | |
(contains? | |
% | |
:radiator-react-native.error-messages/some-key), | |
:val {:foo :bar}, | |
:via [:radiator-react-native.error-messages/or-spec], | |
:in []} | |
{:path [:seq :i1], | |
:pred int?, | |
:val [:foo :bar], | |
:via [:radiator-react-native.error-messages/or-spec], | |
:in [0]})} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment