Skip to main content

let

macro

clojure.test.check.generators/let

(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)))

No examples yet. Be the first to add one!