Hi all. I'm wondering about the best way to document the relationship between a spec and a binding 📚
• I have a spec (s/def ::factor (some-predicates-here)) .
• ...and I have a default db in a re-frame app : (def default-db {:some-key nil}) .
• I want to communicate that :some-key is supposed to adhere to the ::factor spec, for myself and other people reading the code in the future.
• I tried using metadata (def default-db {:some-key ^spec:factor nil}) but nil can't receive metadata.
• I'm doing validation with (valid?... ; my question is just about documenting the relationship.
• A comment is better than nothing but I'm wondering if there's a better, more idiomatic way.
What's the best way to do this? 👀
A bit more context https://thefocus.quest/blog/in-lieu-of-types/.
(s/def ::default-db (s/keys :req [::factor])
https://clojure.org/guides/spec#_entity_maps
Or, if you really want the key to be some-key:
(s/def ::some-key ::factor)
(s/def ::db (s/keys :req-un [::some-key]))Ah, makes sense to cover the whole db with spec. Thanks @clojurians-slack100