Luke Sleeman
01/20/2020, 7:04 AMval myList = listOf {
add("Blah")
add("Foo")
if(somethingIsTrue) {
add("More")
add("Stuff")
}
}
I seem to remember somebody talking about it, or tweeting about it? Possibly it was coming to the standard libraries?tseisel
01/20/2020, 7:05 AMbuildList
.Czar
01/20/2020, 8:21 AMval myList = sequence {
yield("Blah")
yield("Foo")
if (somethingIsTrue) {
yield("More")
yield("Stuff")
}
}.toList()
I'm not sure how significant SequenceBuilder overhead will be though.
There's also the obvious:
val myList = mutableListOf<String>().apply {
add("Blah")
add("Foo")
if(somethingIsTrue) {
add("More")
add("Stuff")
}
}.toList()
Stephan Schroeder
01/20/2020, 11:54 AMval myList = mutableListOf<String>(
"Blah",
"Foo"
).apply {
if(somethingIsTrue) {
add("More")
add("Stuff")
}
}.toList()
Luke Sleeman
01/21/2020, 12:00 AM