This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-04-15
Channels
- # announcements (10)
- # beginners (113)
- # calva (2)
- # cider (75)
- # clj-kondo (1)
- # cljdoc (2)
- # clojure (142)
- # clojure-europe (11)
- # clojure-gamedev (6)
- # clojure-italy (7)
- # clojure-nl (8)
- # clojure-spec (3)
- # clojure-uk (50)
- # clojurescript (47)
- # cursive (7)
- # data-science (22)
- # datomic (12)
- # dirac (3)
- # events (1)
- # fulcro (114)
- # gorilla (1)
- # jackdaw (5)
- # joker (3)
- # kaocha (10)
- # leiningen (1)
- # liberator (2)
- # mount (6)
- # nrepl (1)
- # off-topic (16)
- # pathom (34)
- # pedestal (3)
- # re-frame (19)
- # reagent (11)
- # remote-jobs (5)
- # shadow-cljs (127)
- # spacemacs (12)
- # test-check (15)
- # tools-deps (8)
- # vim (4)
Given a spec, how can I generate random value(s)? Does spec.gen/generate take a spec or is there another fn? Thank you!
clojure.spec.alpha/gen
takes a spec and returns a generator for it.
clojure.spec.gen.alpha/sample
takes a generator and gives you a few examples. Takes an optional number of examples to generate
clojure.spec.alpha/exercise
takes a spec and gives you a seq of pairs, each containing generated example value, and the same value conformed.
Check out their docstrings.
Also, it's highly recommended to read the Spec guide in its entirety (https://clojure.org/guides/spec)
It clears a lot of these things up (including potential gotchas like you need to include test.check
for some of the functionality to work)