Title
s

simon.vergauwen

06/06/2020, 2:19 PM
Does this look correct for an
``Arb.frequency``
function? And would there be any interest for this operator? You could easily derive
``choice``
from this operator. It was inspired by
``frequency``
from
``ScalaTest``
, in contrast to
``choice``
it takes a
``weight``
per
``Arb``
.
s

sam

06/06/2020, 5:36 PM
We have Arb.choose, is that sufficient for what you need?
``````/**
* Returns a stream of values based on weights:
*
* Arb.choose(1 to 'A', 2 to 'B') will generate 'A' 33% of the time
* and 'B' 66% of the time.
*
* @throws IllegalArgumentException If any negative weight is given or only
* weights of zero are given.
*/
fun <A : Any> Arb.Companion.choose(a: Pair<Int, A>, b: Pair<Int, A>, vararg cs: Pair<Int, A>)``````
s

simon.vergauwen

06/07/2020, 8:08 AM
No, that isn’t sufficient for me. I’m using this to create an
``Arb``
from a
``sealed class``
but I want the create an
``Arb``
for every case, and I don’t want them to occur in the same frequency. Example:
``````fun <A> pureIO(arb: Arb<A>): Arb<IO<A>> = arb.map { IO.just(it) }
fun failingIO(): Arb<IO<Nothing>> = Arb.throwable().map { IO.raiseError(it) }

fun <A> <http://Arb.Companion.io|Arb.Companion.io>(arb: Arb<A>): Arb<IO<A>> =
Arb.frequency(5 to pureIO(arb), 1 to failingIO())``````
s

sam

06/07/2020, 9:32 AM
Thats what choose does?
s

simon.vergauwen

06/07/2020, 9:33 AM
Yes, but based on
``A``
not on
``Arb<A>``
``Pair<Int, A>``
vs
``Pair<Int, Arb<A>>``
s

sam

06/07/2020, 11:22 AM
Oh
I have added to master a version that accepts arbs rather than values. I've also added in aliases to frequency to aid discoverability for those from a haskell quickcheck background. https://github.com/kotest/kotest/issues/1499
s

simon.vergauwen

06/07/2020, 6:27 PM
Awesome 🙌