This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-09-09
Channels
- # announcements (1)
- # beginners (166)
- # calva (2)
- # cider (7)
- # clojure (21)
- # clojure-dev (11)
- # clojure-italy (3)
- # clojure-russia (5)
- # clojure-spec (13)
- # clojure-uk (1)
- # clojurescript (251)
- # core-async (2)
- # cursive (14)
- # emacs (6)
- # events (8)
- # figwheel-main (5)
- # fulcro (17)
- # off-topic (8)
- # pedestal (3)
- # tools-deps (17)
to back up a little bit.. suppose I have a deeply nested map data structure, how can I inspect its structure without manually traversing all its composed (s/def)
s ? I could generate an example, but that doesn’t tell me that a specific leaf is specd with a string?
predicate e.g.
plus the example generation is also kinda limited because its predicated on the fact that every predicate I use has a generator
Other question, how do I spec a collection which has the sequence: [string? int? keyword?]
.. Whereby int? keyword? can repeat arbitrary. So something like [sting? int? keyword? int? keyword? int? keyword?]
would be valid?
@basti untested but I think (s/cat :s string? :rest (s/+ (s/cat int? keyword?)))
Yeah, (s/def ::x (s/cat :s string? :rest (s/+ (s/cat :i int? :k keyword?))))
should do it @basti
that’s awesome, thanks @seancorfield 🙂
well, until skynet comes around, it's up to you to assess which spec is trivial to generate automatically, and which ones need your help, @basti
what exactly do you mean by inspect
? there is an s/conform, which destructures and assigns labels to most of the nodes. in which usecase it is not enough for you?
basically convert
(s/def ::name string?)
(s/def ::person (s/keys :req-un [::name]))
(s/def ::registration (s/keys :req-un [::person]))
to
(mapify ::registration)
=> {:person {:name 'cljs.core/string?}}
So that I see the whole structure at one glance.
Meanwhile I wrote a small utility function that converts map specs to my desired structure - will write a blog post about that eventually 🙂@basti at least spec-tools has a spec form parser & visitor, which can walk over all(?) specs. But I guess you already rolled your own.