Sorry, another question that I couldn’t find a good answer for via G. How do I spec a nested structure? Here is the code snippet that I tried.
(s/def ::my-spec (s/cat :a-b (s/cat :s string? :i int?) :s2 string?))
(s/explain-data ::my-spec [["test" 1] "world"])
;; => #:clojure.spec.alpha{:problems [{:path [:a-b :s], :pred clojure.core/string?, :val ["test" 1], :via [:ct-test/my-spec :ct-test/my-spec], :in [0]}], :spec :ct-test/my-spec, :value [["test" 1] "world"]}
I guess I could use a tuple in the spec and that would resolve it but that’s more limiting that s/cat.
Different question? Is there any good way to put these answers into Google?gotcha thanks!
I think you can get the nesting you want by wrapping the inner s/cat with s/spec.
https://clojurians.slack.com/archives/C1B1BB2Q3/p1664745079479859?thread_ts=1664739041.707149&cid=C1B1BB2Q3
(require '[clojure.spec.alpha :as s])
(s/def ::my-spec (s/cat :a-b (s/spec (s/cat :s string? :i int?)) :s2 string?))
(s/valid? ::my-spec [["test" 1] "world"]) ;; true