Skip to content

Fix bugs in gen/fmap documentation #590

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

schmudde
Copy link

@schmudde schmudde commented May 6, 2022

The documentation for clojure.test.check.generators/fmap will throw an error when run.

gen/fmap has a signature of [f gen]. The generators in spec.adoc are being cast to function names in the example calls to gen/fmap (e.g. (gen/string-alphanumeric)). They should be evaluated as a generator (e.g. gen/string-alphanumeric).

The current evaluation result is an Execution error: class clojure.test.check.generators.Generator cannot be cast to class clojure.lang.IFn. The proposed changes allow for proper execution.

  • Have you read the guidelines for contributing?
  • Have you signed the Clojure Contributor Agreement?
  • Have you verified your asciidoc markup is correct?
The documentation for `clojure.test.check.generators/fmap` will throw an error when run. 

`gen/fmap` has a signature of `[f gen]`. The generators in spec.adoc are being cast to function names in the call to `gen/fmap` (e.g. `(gen/string-alphanumeric)`). They should be evaluated as a generator (e.g. `gen/string-alphanumeric`).

The current evaluation result is an *Execution error: class clojure.test.check.generators.Generator cannot be cast to class clojure.lang.IFn*. The proposed changes allow for proper execution.
@puredanger
Copy link
Member

fmap in these examples is not clojure.test.check.generators/fmap, it's clojure.spec.gen.alpha/fmap. The spec generators wrap and modify the test.check generator functions to take generator thunks, not generators. So this code is correct as written. The changes you suggest would be correct if using the c.t.c.g/fmap directly (but as seen in the guide it's (require '[clojure.spec.gen.alpha :as gen])).

@puredanger puredanger closed this May 6, 2022
@schmudde
Copy link
Author

schmudde commented May 6, 2022

I see. Hence the big yellow box in this section that says:

The last option [3. Use test.check or other test.check compatible libraries] requires a runtime dependency on test.check so the first two options [1. Let spec create a generator based on a predicate/spec 2. Create your own generator from the tools in clojure.spec.gen.alpha] are strongly preferred over using test.check directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants