https://kotlinlang.org logo
#kotest-contributors
Title
# kotest-contributors
e

Emil Kantis

01/30/2023, 7:39 PM
@sam @mitch any opinions on https://github.com/kotest/kotest/pull/3358? Good idea to add? I'm also a bit bothered by the naming. I would like to have something like:
Copy code
val companyDepartmentArb = Arb.bind<CompanyDepartment>(
  Location::class to myLocationArb,  
  Person::name to Arb.string(codepoints = Codepoint.alphanumeric()),
  Person::age to <http://Arb.int|Arb.int>(0..120),
)
Right now you'd have to do:
Copy code
val companyDepartmentArb = Arb.bind<CompanyDepartment>(
  providedArbs = mapOf(Location::class to myLocationArb),  
  arbsForProperties = mapOf(
    Person::name to Arb.string(codepoints = Codepoint.alphanumeric()),
    Person::age to <http://Arb.int|Arb.int>(0..120),
  )
)
Plus the naming feels a bit off.
providedArbs
doesn't say how it's different from
arbsForProperties
, but changing it means breaking backwards compat.. Perhaps easiest to just add new methods altogether and deprecate the current ones, but that's also a bit invasive..
l

LeoColman

01/30/2023, 8:09 PM
If they're not insanely different/confusing/broken we can add the new options and keep them as aliases
s

sam

01/30/2023, 9:23 PM
I like the first idea.
m

mitch

01/30/2023, 9:23 PM
+1 I think the first idea is really clean
e

Emil Kantis

01/31/2023, 6:41 AM
Downside is it's strict on the order of arguments. Would be something like. Perhaps not an issue though
Copy code
fun Arb.bind(
  vararg classArbs: Pair<KClass, Arb>, 
  propArb: Pair<KProperty, Arb>,
  vararg propArbs: Pair<KProperty, Arb>,
)
Generics omitted for readability.. 🙂
Another option.. trying to make it order-independent. 🙂
l

LeoColman

01/31/2023, 2:21 PM
I don think you can have 2 varargs
e

Emil Kantis

01/31/2023, 2:21 PM
you're right 🙂
5 Views