Shabinder Singh
07/02/2020, 7:37 AMvar countryList= mutableSetOf<String>()
I want to somehow create empty sets as following -
var us= mutableSetOf<String>()
var in= mutableSetOf<String>()
var br= mutableSetOf<String>()
but i get elements in countryList set dynamically from internet , so how do i create empty sets named as above dynamically?
us, in br are fetched from internet and added to countryList set dynamically.natpryce
07/02/2020, 7:43 AMdeactivateduser
07/02/2020, 7:43 AMJonathan Mew
07/02/2020, 7:44 AMval c = listOf('us', 'in', 'br')
val sets = c.associate { it to mutableSetOf<String>() }
Jonathan Mew
07/02/2020, 7:46 AMJonathan Mew
07/02/2020, 7:47 AMShabinder Singh
07/02/2020, 7:47 AMShabinder Singh
07/02/2020, 7:49 AMdeactivateduser
07/02/2020, 7:52 AMdeactivateduser
07/02/2020, 7:52 AMShabinder Singh
07/02/2020, 7:53 AMJonathan Mew
07/02/2020, 8:02 AMShabinder Singh
07/02/2020, 8:05 AMdeactivateduser
07/02/2020, 8:07 AMShabinder Singh
07/02/2020, 8:12 AMvar dataList = mutableListOf<ProxyList>()
var proxyList = mutableListOf<String>()
var countryList= mutableSetOf<String>()
data class ProxyData(
val data: MutableList<ProxyList>
){
companion object{
}
init {
dataList = data
}
}
data class ProxyList(
val country:String,
val country_code: String,
var createdAt: String
) {
init {
countryList.add(country_code)
}
}
private fun proxyIntoSet(){
val c = countryList
val sets = c.associateWith { mutableSetOf<String>() }
}
private fun organisingProxies(){
for (proxy in dataList) {
proxy.country_code.add(proxy.createdAt)
}
}
all proxylist objects and proxydata objects are created at runtime
sample data input to these classes ove iternet is somewhat like this
{
"country":"United States",
"country_code":"us",
"createdAt":"123456"
Shabinder Singh
07/02/2020, 8:15 AMdeactivateduser
07/02/2020, 8:19 AMproxy.country_code.add(proxy.createdAt)
? What is the purpose of doing this, since you already have the createdAt field anyway? Sorry still can't really grasp what is the ultimate goal. Or maybe you just want to append the createdAt to the country_code ?Shabinder Singh
07/02/2020, 8:22 AMShabinder Singh
07/02/2020, 8:23 AMShabinder Singh
07/02/2020, 8:25 AMnatpryce
07/02/2020, 8:25 AMdataList.groupBy(ProxyList::country)
should do what you want.Shabinder Singh
07/02/2020, 8:28 AMShabinder Singh
07/02/2020, 8:29 AMnatpryce
07/02/2020, 8:32 AMdataList.groupBy(ProxyList::countryCode,ProxyList::createdAt).mapValues { k, v -> v.toSet() }
Shabinder Singh
07/02/2020, 8:34 AMdeactivateduser
07/02/2020, 10:10 AM