sequential? is not really adding any value here - using a regex op will *only* match something that's sequential.
The other thing to know here is that s/and creates a generator that generates based on the first spec, then filters based on the subsequent ones. So if you wanted to do sequences of an *even* number of numbers you could do: (s/exercise (s/and (s/* integer?) #(even? (count %)))) This will generate sequences of numbers and filter all that don't have an even number of elements. If your generator is too broad or your filters aren't selective enough, you may need to provide a custom generator: ;; generator creates any sequence of nums, but only want ones containing 42 (s/exercise (s/and (s/* integer?) #(some #{42} %))) ;; fails ;; add custom generator that generates random seq of nums, then injects 42 (s/def ::nums (s/* integer?)) (s/exercise (s/with-gen (s/and ::nums #(some #{42} %)) (fn [] (gen/fmap #(conj % 42) (s/gen ::nums))))) On Friday, June 10, 2016 at 10:01:48 AM UTC-5, Frank Versnel wrote: > > Hi, > > I'm currently playing around with clojure spec trying to write a spec for > an old program I wrote and stumbled upon the following: > > Whenever I try to generate something that is both sequential and something > else it doesn't really work most of the time. > For example when I try to create a sequence of integers like this: > > (s/exercise (s/and sequential? (s/* integer?))) > > It will often fail to produce anything in the first 100 tries while: > > (s/exercise (s/and (s/* integer?))) > > works flawlessly every time. Maybe I'm doing something wrong or maybe I do > need to > write a custom generator for the sequential bit? > > Best regards, > > Frank > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.