Fork me on GitHub

i have a dumb spec question that unfortunately is in the "difficult to google" category - say i had a sequence with the following structure: [1 "a" 2 "b" "c" 0 3 "d" "e" "f"] the pattern here is a number which indicates how many following items there are directly in the sequence -- i adjusted spacing above to hopefully make that clearer this is of crouse trivial to express if the following items are in another sequence, but scanning the docs i can't see a way to spec the flat version of this -- note that this isn't motivated by any important use case, more just part of me trying to learn spec so feel free to treat this as pure curiosity

Alex Miller (Clojure team)19:01:19

regex specs combine to spec one flat sequence

Alex Miller (Clojure team)19:01:05

so you could do something like (s/* (s/& (s/cat :c nat-int? :s (s/* string?)) #(= (:c %) (count (:s %)))))

💡 4

thanks! that is extremely straightforward -- i feel like i had something similar but surely missed something basic and made a wrong assumption. will compare and learn -- thanks again.

Alex Miller (Clojure team)19:01:28

it's very important to use s/&, not s/and there

Alex Miller (Clojure team)19:01:49

s/and is not a regex spec and will expect a new nested collection boundary


yeah i had the & but i think i had a surrounding cat there that was throwing it all off