I know that in this particular example can be problem with eager evaluation which is not problem in Haskell since it is lazy, however, we can solve it by adding another associated function which chooses from closures instead of values. In other words, do it exactly like it is done for Result with and/and_then and or/or_else functions.
Can we include something like frequency from Haskell's QuickCheck? It will generalize this pattern and make it more convenient to use, for example:
The implementation can be something like this:
I know that in this particular example can be problem with eager evaluation which is not problem in Haskell since it is lazy, however, we can solve it by adding another associated function which chooses from closures instead of values. In other words, do it exactly like it is done for
Result
withand
/and_then
andor
/or_else
functions.What do you think?