Another nice little addition I find myself using (...
# kotest
d
Another nice little addition I find myself using (if not there already?) is some kind of:
Copy code
fun <T> Arb.Companion.of(arb: Arb<T>, vararg values: T): Arb<T> = arbitrary { rs ->
    Arb.of(arb.next(rs), *values).next(rs)
}
used to make a new arb or choose from an existing value of the same type (I'm not sure if I implemented this in the best way though...)
s
Arb.choose ?
d
Arb.choose chooses between two constant values, but it doesn't choose between a constant one or generating a new one, does it?
But the weights might be useful here too... so instead of
of
it could very well be
choose()
for my implementation.
s
I'm sure there's one tht takes arbs
d
Yeah, but then it's only arbs, not one arb and one value
s
you could wrap the values in arb.constant
d
Yeah, I just noticed now... I new I missed something! It is a bit more verbose, but at least possible!
s
yep
d
I wonder if people would mind a new general extension function
fun <T> T.toArb()  = Arb.constant(this)
?
s
fun <T> T.contstant()  = Arb.constant(this)
3 more chars
you could add that
d
T.constant()
isn't a bit too ambiguous?
s
well yeah I suppose to
do toArb then
d
I guess the best of both worlds:
Copy code
fun <T> T.toConstArb() = Arb.constant(this)
Unless you think you'll never use toArb() for something else...
s
I think toArb is good