Add nullable/2 generator#221
Conversation
As discussed in whatyouhide#220, this PR implements a `nullable/2` generator. It returns either the result of the generator given as the first argument or `nil`. The default ratio between the two possibilities is 0.5, but can be adjusted using the `:ratio` option. Fixes whatyouhide#220
|
One pattern that I've also found useful is to be able to say |
I think the API surface is already large and that doesn't seem like a very useful addition. Also same as: [some, other, gen]
|> one_of()
|> nullable() |
whatyouhide
left a comment
There was a problem hiding this comment.
Nice start! I left comments with minor tweaks. Also, why did you decide to force < 1.0 instead of <= 1.0?
I don't think that is the same as what I was suggesting. In your code, However, I agree that the API surface is already large. I'll leave it as is. |
Co-authored-by: Andrea Leopardi <[email protected]>
Co-authored-by: Andrea Leopardi <[email protected]>
Co-authored-by: Andrea Leopardi <[email protected]>
Co-authored-by: Andrea Leopardi <[email protected]>
Co-authored-by: Andrea Leopardi <[email protected]>
|
Your review suggestions are much appreciated. I've applied all of them. As for the choice to force Also, when I wrote up the initial implementation, I tried to do funky division stuff, so I wanted to guard against an accidental division by zero. This is not a problem anymore, so I'm fine with relaxing the boundaries if you want. |
Solved by
Then |
The nullable ratio is now allowed to be 0.0 and 1.0.
Correct.
0.0 also wasn't allowed, but I've pushed a new commit that relaxes the constraints. |
Pull Request Test Coverage Report for Build dac84709b7ef95616a3e131ecd7ff9dd36a4d712-PR-221Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
|
Thanks @Munksgaard 💟 |
|
Thank you, and thanks for the presentation at Goatmire ❤️ (we didn't get to chat, but I still enjoyed it) |
As discussed in #220, this PR implements a
nullable/2generator. It returns either the result of the generator given as the first argument ornil. The default ratio between the two possibilities is 0.5, but can be adjusted using the:ratiooption.Fixes #220