Fork me on GitHub
#clojure-spec
<
2021-02-05
>
Daniel Stephens12:02:26

Hi, is there a better way to have a completely custom spec generator?

(let [my-custom-generating-fn #(do {:something (rand-int 100) :complicated (rand-int 200)})

      g (gen/fmap #(%) (gen/return my-custom-generating-fn))]
  (gen/generate g))
all the examples I found start from some primitive like (gen/int) . Feels like what I was trying is intended to be difficult, is that because it doesn't follow some underlying random seed or something, or am I just missing the key bit

Alex Miller (Clojure team)13:02:58

Correct - generally generators should control randomness, not introduce their own sources of randomness, as that makes it impossible to either shrink or regen from the same seed

Daniel Stephens13:02:56

very useful, thanks Alex

borkdude14:02:40

A one time shout out: finding specs by keyword is now a lot easier in clojure-lsp. You can even navigate to the definition of a spec via the keyword.

😍 12