Colton Idle
05/01/2024, 5:21 AMJordan Gout
05/01/2024, 5:50 AMval firstname: String? = "John"
val middlename: String? = " "
val lastname: String? = null
val names: String = listOf(firstname, middlename, lastname)
.filter { !it.isNullOrBlank() }
.joinToString(" ")
Adam S
05/01/2024, 7:01 AM.joinToString(" ") { it.trim() }
Adam S
05/01/2024, 7:03 AMJordan Gout
05/01/2024, 7:03 AMJoffrey
05/01/2024, 7:44 AMisNullOrBlank
the trim doesn't need to be first. It avoids having one more operation since the map
can be merged with joinToString
Joffrey
05/01/2024, 7:47 AMJordan Gout
05/01/2024, 7:50 AMIt avoids having one more operation since theindeed 💯can be merged withmap
joinToString
Colton Idle
05/01/2024, 12:48 PMCLOVIS
05/01/2024, 3:35 PMlistOfNotNull(firstName, middleName, lastName)
.joinToString(" ")
Joffrey
05/01/2024, 3:36 PMCLOVIS
05/01/2024, 3:36 PMnull
when missing.Joffrey
05/01/2024, 3:37 PM.takeIf { it.isNotBlank() }
is a simple way of cleaning things upephemient
05/01/2024, 6:16 PM.ifBlank { null }
Joffrey
05/01/2024, 6:17 PMColton Idle
05/29/2024, 6:28 PMlistOf(first, middle, last)
.mapNotNull { it.trim().ifBlank { null } }
.joinToString(" ")
Colton Idle
05/30/2024, 3:35 PMifBlank
all the time now. nice convenience methodCLOVIS
05/30/2024, 3:35 PMifEmpty
for collectionsJoffrey
05/30/2024, 3:36 PM