Fork me on GitHub

I’d like to simplify this API, but I’m not sure how to create both a “variable” and a function-reference from the same parameter


Any ideas?


I might have to use a macro I guess

Alex Miller (Clojure team)14:03:26

if you start from the symbol, it’s easy enough to get the meta from there


might not be that easy from cljs

Alex Miller (Clojure team)14:03:07

ah, true, didn’t notice that


yeah, unfortunately that doesn’t work


Just starting with custom generators, and I have only looked at the underlying code in clojure.test.check.generators a bit, and didn’t notice if there was a more straight-forward way to use custom generators without input arguments. clojure.test.check.generator’s own uuid is an interesting example, but it relies on an internally passed random number (while ignoring size) and defines itself with namespace internal functions.

(s/def ::saddle (s/with-gen
                (s/and string? (partial re-matches saddle.regex))
                #(gen/fmap (fn [_] (zero-arity-gen)) (gen/return nil))))


@waffletower this is generally discouraged since it sidesteps most of the test.check orchestration -- it should be possible for you to write any generator you need using the built in combinators


Is your specific problem about generating a string that matches a regex?


the generator doesn’t need shrinking as with gen/uuid, and it currently uses RNG internally. I could use RNG from the generator namespace instead — which seems to suggest I could continue using gen/fmap


you can opt-out of shrinking by wrapping with gen/no-shrink


using the randomness from test.check means that at least your generator (and any composition including it) is deterministic


@waffletower if you'd like to share the details of the generator you already have I could suggest how to rewrite it