Daniele B
05/12/2021, 7:24 AMList<String>
like this:
val myList = listOf("paramA","paramB","paramC")
I can enforce an API like this?
fun myFunc (paramA: String, paramB: String, paramC: String)
basically a function, which has those strings as names for String arguments?Vitaliy Zarubin
05/12/2021, 7:30 AMDaniele B
05/12/2021, 7:41 AMephemient
05/12/2021, 7:49 AMVitaliy Zarubin
05/12/2021, 7:50 AMderek
05/12/2021, 7:50 AMfun hello(nameA: String, nameB: String, nameC: String): Unit = TODO()
fun main() {
val parmsName = ::hello.parameters.map{
it.name
}
println(parmsName)
}
Daniele B
05/12/2021, 7:54 AMparameters
shows as “unresolved”derek
05/12/2021, 8:08 AMDaniele B
05/12/2021, 8:14 AMephemient
05/12/2021, 8:34 AMval names = listOf(...)
val function = makeFunction(names)
even with something like that, function
has to have a type when it's declared, you can't change that at runtimeDaniele B
05/12/2021, 8:39 AMJoost Klitsie
05/12/2021, 9:02 AMDaniele B
05/12/2021, 9:12 AM"param1=value1¶m2=value2¶m3=value3"
Where the number and the names of the params should be defined by the library user.
e.g. this could be all possibile IDs:
"country=Belgium"
"listType=ALL&filter=name"
"id=203"
So, I want to give the chance to the library user to hardcode the parameter names, and then being able to populate each of them with a simple function.
This ID should be univocally identified as the String format I mentioned above:
“param1=value1¶m2=value2¶m3=value3”Joost Klitsie
05/12/2021, 9:18 AMDaniele B
05/12/2021, 9:20 AMVitaliy Zarubin
05/12/2021, 9:26 AMJoost Klitsie
05/12/2021, 9:35 AMDaniele B
05/12/2021, 9:36 AMJoost Klitsie
05/12/2021, 9:40 AMDaniele B
05/12/2021, 9:40 AMVitaliy Zarubin
05/12/2021, 9:41 AMRoukanken
05/12/2021, 9:43 AMDaniele B
05/12/2021, 9:47 AMRoukanken
05/12/2021, 9:49 AMDaniele B
05/12/2021, 9:49 AMparam1=value1¶m2=value2¶m3=value3
to MyDataClass(param1 = value1, param2 = value2, param3 = value3)
and back
with Serialization?Roukanken
05/12/2021, 9:56 AMtype=MyDataClass¶m1=value1¶m2=value2¶m3=value3
) then it should be possible too
I haven't looked into custom formats too deep yet tho...
Here is some reading for it: https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/formats.mdDaniele B
05/12/2021, 9:58 AM