How would I go about making a certain key necessary when that key can exist at different depths in a map (and it only needs to exist at least once)? Do I need to normalize the map and put it at one level or is there another way?
Use clojure.walk to see if exists at least once?
How would I go about incorporating that into a spec validity check?
(s/def ::guarantee-key-in-map (write-your-fn-here))
(s/def ::my-map
(s/and ::guarantee-key-in-map
(s/keys :req [:other-key
... and so onsomething like that?
(s/valid? ::my-map some-map)
I don’t write that many specs, so don’t copy verbatim 😄 it probably doesn’t compile
Or simpler, without the map thing:
(s/def ::guarantee-key-in-map (write-your-fn-here))
(s/valid? ::guarantee-key-in-map some-map)The key takeaway is that your spec is something separate from e.g. s/keys. I don’t think you can use s/keys to say arbitrary things about certain values in your map. But you can do so with a separate spec that you can s/and
Anybody, feel free to take the wheel and show @slack1079 how I’m wrong 🙂
I think I only now got what Alex Miller was alluding to in the post above. Feel kinda dumb now. Thank you^^ I think I got my test case working the way I want it to. Now I just need to remember where I wanted to use this 😅