Skip to content
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

no Gen.let or heterogeneous sequence/tuple? #276

Closed
johanatan opened this issue Oct 5, 2018 · 7 comments
Closed

no Gen.let or heterogeneous sequence/tuple? #276

johanatan opened this issue Oct 5, 2018 · 7 comments

Comments

@johanatan
Copy link

johanatan commented Oct 5, 2018

i.e.,
https://github.com/clojure/test.check/blob/master/src/main/clojure/clojure/test/check/generators.cljc#L1585-L1588

and
https://github.com/clojure/test.check/blob/master/src/main/clojure/clojure/test/check/generators.cljc#L82-L87

Any workarounds approaching these other than nesting flatMaps (which would become rather unwieldy)?

@johanatan
Copy link
Author

johanatan commented Oct 5, 2018

Ah, I found Gen<DEST_TYPE>.map(G0, G1, ... GN) (now called zipWith). That should suffice for this.

@johanatan
Copy link
Author

Also, Gen.compose.

@CodaFi
Copy link
Member

CodaFi commented Oct 6, 2018

Gen.compose is definitely your friend here for tuples of large arity.

@johanatan
Copy link
Author

Does that mean I have to define classes to hold them or is there a way to actually produce a Tuple directly from Gen.compose?

@CodaFi
Copy link
Member

CodaFi commented Oct 6, 2018

Nope, it's polymorphic in the return type of the builder closure. All you've gotta do is provide a block that acts as a stencil for your tuple

let generator = Gen.compose { (builder) -> (Int, Float, Array<Int>) in
  return (builder.generate(), builder.generate(), builder.generate())
}

@johanatan
Copy link
Author

Awesome. Thanks!

@CodaFi
Copy link
Member

CodaFi commented Oct 8, 2018

Given that I think you've got your answer, I'm going to close this out. Please feel free to reopen it if I'm wrong about that part.

@CodaFi CodaFi closed this as completed Oct 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants