[spec] `let` ported from `test.check/let` to `clojure.spec.gen`

Description

When using `clojure.spec` for elaborate specifications and `clojure.spec.gen` for generative testing, developers often find themselves writing code which heavily relies on `clojure.spec.gen/fmap`. This is sometimes unnatural and difficult to read.

To make writing custom generators easier, this patch ports `test.check/let` to `clojure.spec.gen`. Now developers can write generators more simply.

Environment

None

Activity

Show:
import
July 24, 2016, 11:55 PM

Comment made by: xcthulhu

For example, if a user wanted to make a generator of vectors with length between 5 and 11 or 20 to 40 elements, consisting of keywords which were either `:a` or `:b`, they would have to write something like:

With this patch they could write this as:

Rick Moynihan
July 6, 2017, 12:57 PM

Ran into the lack of this useful macro recently. And spoke to @gfredricks about it on slack. He mentioned that the supplied patch looks to be a complete reimplementation of gen/let with different behaviour.

He suggested an alternative might be to have the gen/let macro make a require call, which when succeeds just expands to use the test.check let implementation. If the require fails the macro can expand into code that raises an appropriate error. Presumably indicating that test.check needs to be included as a dependency.

e.g.

Assignee

Unassigned

Reporter

import

Labels

Approval

None

Patch

Code and Test

Affects versions

Priority

Minor
Configure