-
Notifications
You must be signed in to change notification settings - Fork 30
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
Generate lazily evaluated sequences #154
Comments
Perhaps with a custom generator |
I hope that's possible, but I don't know how. AFAIK you can't easily mix computation expressions. |
Maybe we could invent some kind of ... computation expression transformer 😉 |
Sure! A computation expression (CE) is really a class (a type that represents objects that can have properties, methods, and events). So it should be possible to define a CE with a non-parameterless constructor taking another CE as a parameter, similar to this one. |
It is easy to lazily obtain a given number of values from some generator. However, I don't know how to create This is the test to which @cmeeren referred. I created this PR to change that test into one that is more efficient and more idiomatic. |
Edit: Nevermind, I see that for the |
The unusual thing about your use case is that you don't care about shrinking. It is trivial to create a shrunken list that doesn't contain You do this by forcing the list generator to create 1000 values of the underlying generator with the hope that the set of those 1000 values is equal to the set of values in the sample space. An interesting alternative for an integral (aka discrete) generator is to output a lazy sequence of all values in its sample space. Lazy is necessary here since the sample space might be infinite. In your use case, the sample space is finite, so you could either find |
@cmeeren and I agreed that that PR was not an improvement. I have a better idea though. The actual problem @cmeeren wants to solve is (almost) exactly what The only problem is that the return type of |
When writing tests for Hedgehog.Experimental I came across the need for just checking if a property holds at least some of the time. For example, when testing
withNull
, I create a property I run once that generates a list of, say, 1000 items and checks if it containsnull
.When testing if a property holds some of the time, one might need to generate many items to avoid false negatives. But most of the time you might get a positive fairly quickly, say after 10 items and the rest of the 990 generated items are wasted. I thought about using
Gen.seq
instead ofGen.list
, but it just generates a list and passes it toSeq.ofList
and thus provides no performance benefits.Is it possible to have
Gen.seq
actually generate a lazily evaluated sequence?The text was updated successfully, but these errors were encountered: