christophsturm
03/31/2021, 2:24 PMusers = listOf("klaus", "sepperl")+if (addChris) listOf("chris") else listOf()
Luke
03/31/2021, 2:30 PMusers = buildList {
addAll("klaus", "sepperl")
if (addChris) add("chris")
}
christophsturm
03/31/2021, 2:37 PMZach Klippenstein (he/him) [MOD]
03/31/2021, 3:08 PMelse listOf()
is pretty verbose too. And i think it’s dangerous to try to minimize “verbosity”. It’s much more important to maximize readability, and sometimes going too far down the verbosity route can make code harder to read. The buildList
code is extremely readable imo. There’s zero code there that doesn’t express something relevant about what it’s doing.christophsturm
03/31/2021, 3:17 PMusers= buildList("klaus", "sepperl") { if (addChris) add("chris") }
Luke
03/31/2021, 5:24 PMusers = mutableListOf("klaus", "sepperl").apply {
if (addChris) add("chris")
} // .toList() if you want a read-only list
ilya.gorbunov
04/01/2021, 4:15 PMlistOfNotNull("klaus", "sepperl", "chris".takeIf { addChris})
christophsturm
04/01/2021, 4:16 PM