(gen-let bindings & body)Macro for building generators using values from other generators. Uses a binding vector with the same syntax as clojure.core/let, where the right-hand side of the binding pairs are generators, and the left-hand side are names (or destructuring forms) for generated values.
Subsequent generator expressions can refer to the previously bound values, in the same way as clojure.core/let.
The body of the let can be either a value or a generator, and does
the expected thing in either case. In this way let provides the
functionality of both bind and fmap.
Examples:
(gen/let [strs (gen/not-empty (gen/list gen/string)) s (gen/elements strs)] {:some-strings strs :one-of-those-strings s})
;; generates collections of "users" that have integer IDs ;; from 0...N-1, but are in a random order (gen/let [users (gen/list (gen/hash-map :name gen/string-ascii :age gen/nat))] (->> users (map #(assoc %2 :id %1) (range)) (gen/shuffle)))
Macro for building generators using values from other generators.
Uses a binding vector with the same syntax as clojure.core/let,
where the right-hand side of the binding pairs are generators, and
the left-hand side are names (or destructuring forms) for generated
values.
Subsequent generator expressions can refer to the previously bound
values, in the same way as clojure.core/let.
The body of the let can be either a value or a generator, and does
the expected thing in either case. In this way let provides the
functionality of both `bind` and `fmap`.
Examples:
(gen/let [strs (gen/not-empty (gen/list gen/string))
s (gen/elements strs)]
{:some-strings strs
:one-of-those-strings s})
;; generates collections of "users" that have integer IDs
;; from 0...N-1, but are in a random order
(gen/let [users (gen/list (gen/hash-map :name gen/string-ascii
:age gen/nat))]
(->> users
(map #(assoc %2 :id %1) (range))
(gen/shuffle)))(non-empty-string-alphanumeric)Generator for non-empty alphanumeric strings
Generator for non-empty alphanumeric strings
(vector-distinct-by & args)Lazy loaded version of clojure.test.check.generators/vector-distinct-by
Lazy loaded version of clojure.test.check.generators/vector-distinct-by
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |