clojure-spec

About: http://clojure.org/about/spec Guide: http://clojure.org/guides/spec API: https://clojure.github.io/spec.alpha/clojure.spec.alpha-api.html
Daniel Stephens 2021-02-05T12:56:26.027Z

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

alexmiller 2021-02-05T13:40:58.029Z

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 Stephens 2021-02-05T13:53:56.029100Z

very useful, thanks Alex

borkdude 2021-02-05T14:15:40.030Z

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.

😍 4