This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-08-06
Channels
- # aleph (1)
- # beginners (180)
- # calva (16)
- # cider (29)
- # clj-kondo (47)
- # cljsrn (5)
- # clojure (40)
- # clojure-dev (39)
- # clojure-europe (1)
- # clojure-italy (25)
- # clojure-nl (9)
- # clojure-russia (1)
- # clojure-spec (8)
- # clojure-uk (83)
- # clojurescript (54)
- # core-async (2)
- # datomic (20)
- # defnpodcast (7)
- # figwheel (6)
- # fulcro (6)
- # jobs (5)
- # joker (4)
- # kaocha (4)
- # luminus (4)
- # off-topic (8)
- # onyx (6)
- # pathom (14)
- # re-frame (28)
- # reagent (30)
- # remote-jobs (2)
- # shadow-cljs (88)
- # spacemacs (2)
- # specter (17)
- # sql (25)
- # tools-deps (78)
- # xtdb (1)
- # yada (2)
$ clj -Srepro
Clojure 1.10.1
user=> (require '[clojure.spec.alpha :as s])
nil
user=> (require '[clojure.spec.gen.alpha :as sg])
nil
user=> (require '[clojure.spec.test.alpha :as st])
nil
user=> (s/def ::vec vector?)
:user/vec
user=> (s/def ::str string?)
:user/str
user=> (s/def ::str-vec (s/coll-of ::str :kind ::vec))
:user/str-vec
user=> (sg/generate (s/gen (s/coll-of string? :kind vector?)))
["2m4A8TKjUU5TJ61KkKRzbnk2z21" "xAvkdc78i5qo6O8Gf6" "cHbZwfz88d6xZj5qp54L5g" "K6MdrEaiFWm2P27BCD1913h9r1" "2jpUYE74Vvf" "PG9SrB729W5pWo6G5xt7K28tR5M33" "DTAJijHs2t9mEC" "6zkimTFtp51q698N" "eAgGEU08gJF7R5C2tb6ZdcTRO" "Ewx60Cb94NWxMMXjQJn"]
user=> (sg/generate (s/gen ::str-vec))
Execution error (ExceptionInfo) at clojure.test.check.generators/such-that-helper (generators.cljc:320).
Couldn't satisfy such-that predicate after 100 tries.
user=>
@dorab :kind
should not be a spec, it should be a predicate
If you define ::str-vec
with :kind vector?
it works just as expected.
If you read the docstring for s/every
(which applies to s/coll-of
), it says
:kind - a pred that the collection type must satisfy, e.g. vector?
(default nil) Note that if :kind is specified and :into is
not, this pred must generate in order for every to generate.
Predicates can be treated as specs, but specs are not predicates (in general).