Colton Idle

03/16/2022, 2:40 AM
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?
private fun Person.prettyPrint() =
        "${} ${} ${}"

Adam Powell

03/16/2022, 2:50 AM
use a collection and
, but also 🙂
☝️ 2
☝️🏻 1

Colton Idle

03/16/2022, 4:08 AM
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.

Richard Gomez

03/16/2022, 1:32 PM
For this type of thing you could also just write the different formats explicitly in a conditional statement. For example:
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 }


03/16/2022, 4:13 PM
as a convenience, if some parts may be null and you want to skip them,
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