https://kotlinlang.org logo
#kotest
Title
# kotest
d

dave08

05/24/2021, 12:44 PM
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

sam

05/24/2021, 1:23 PM
Arb.choose ?
d

dave08

05/24/2021, 1:25 PM
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

sam

05/24/2021, 2:20 PM
I'm sure there's one tht takes arbs
d

dave08

05/24/2021, 2:21 PM
Yeah, but then it's only arbs, not one arb and one value
s

sam

05/24/2021, 2:22 PM
you could wrap the values in arb.constant
d

dave08

05/24/2021, 2:23 PM
Yeah, I just noticed now... I new I missed something! It is a bit more verbose, but at least possible!
s

sam

05/24/2021, 2:23 PM
yep
d

dave08

05/24/2021, 2:25 PM
I wonder if people would mind a new general extension function
fun <T> T.toArb()  = Arb.constant(this)
?
s

sam

05/24/2021, 2:25 PM
fun <T> T.contstant()  = Arb.constant(this)
3 more chars
you could add that
d

dave08

05/24/2021, 2:27 PM
T.constant()
isn't a bit too ambiguous?
s

sam

05/24/2021, 2:27 PM
well yeah I suppose to
do toArb then
d

dave08

05/24/2021, 2:31 PM
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

sam

05/24/2021, 2:34 PM
I think toArb is good
3 Views