This method works nicely if a person has a middle ...
# codereview
This method works nicely if a person has a middle name, but if they don't. Then it print
Notice the two dots are supposed to show that there are two spaces. What's a convenient way of only having a single space?
Copy code
private fun Person.prettyPrint() =
        "${} ${} ${}"
☝️ 2
☝🏻 1
Yeah. I have that website favorited. In this case, the data model and everything is already created and I'm just trying to move this bug fix along. I did let them know that we could/should probably just keep everything as a single string.
For this type of thing you could also just write the different formats explicitly in a conditional statement. For example:
Copy code
data class Component(val type: String, val namespace: String? = null, val name: String, val version: String) {
    val displayName: String by lazy { if (namespace != null) "$namespace:$name" else name }
as a convenience, if some parts may be null and you want to skip them,
Copy code
listOfNotNull(first, middle, last).joinToString(" ")
.takeIf { it.isNotEmpty() }
to make empty strings into null so that
skips them) but yeah, human names definitely don't all fit that model
👍 2