clojure-spec

Noel Rivas 2025-04-23T03:47:39.383219Z

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? 👀

Noel Rivas 2025-04-23T03:48:57.998039Z

A bit more context https://thefocus.quest/blog/in-lieu-of-types/.

walterl 2025-04-23T09:41:22.652559Z

(s/def ::default-db (s/keys :req [::factor]) https://clojure.org/guides/spec#_entity_maps

walterl 2025-04-23T09:42:57.971769Z

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]))

Noel Rivas 2025-04-23T14:21:57.969569Z

Ah, makes sense to cover the whole db with spec. Thanks @clojurians-slack100

👍 1