Marshall
09/29/2024, 11:58 AMlistOf(
someString1 if someString1 is not null,
someString2,
someString3 if someString3 is digits only
)
?jamshedalamqaderi
09/29/2024, 12:03 PMlistOf()
it would be value or null.
listOf(
if(name.contains("J")) name else null,
if(name.contains("c")) name else null,
).filterNotNull()
Marshall
09/29/2024, 12:03 PMGleb Minaev
09/29/2024, 12:11 PMlistOfNotNull(...)
is a bit shorter 🙂Marshall
09/29/2024, 12:14 PMGleb Minaev
09/29/2024, 12:15 PMlistOf(...).filterNotNull()
.Marshall
09/29/2024, 12:15 PMMarshall
09/29/2024, 12:16 PMMarshall
09/29/2024, 12:19 PMGleb Minaev
09/29/2024, 12:23 PMMarshall
09/29/2024, 12:24 PMJohann Pardanaud
09/29/2024, 12:25 PMbuildList
in this case:
buildList {
if (someString1 != null) add(someString1)
add(someString2)
if (someString3 != null) add(someString3)
}
Marshall
09/29/2024, 12:27 PMDaniel Pitts
09/29/2024, 2:39 PMbuildList
the most flexible way to do this.Shawn
09/29/2024, 4:31 PMlistOfNotNull(nullableString, someString2, someString3.takeIf { it.all(Char::isDigit) })
but buildList {}
is probably a better option overallDaniel Pitts
09/29/2024, 4:43 PM