Why do we not have a `buildString` which takes a s...
# stdlib
n
Why do we not have a
buildString
which takes a separator as an optional parameter? Right now I use e.g.
buildList { ... add(..) }.joinToString(" ")
but
buildString(" ") { ... add(...) }
would be nicer. And perhaps also supports the "prefix" and "suffix" from Java's
StringJoiner
?
7
👍 1
l
You can use an extension to append with a space if you dislike joinTo/joinToString
☝️ 1
a
Extension function for
StringBuilder
probably can't handle something like:
Copy code
buildList {
  repeat(3) {
    add("a")
    add("b")
  }
}.joinToString(" ")
@nkiesel I guess what you want is just simply this?
Copy code
fun joinToString(
        delimiter: CharSequence,
        prefix: CharSequence = "",
        suffix: CharSequence = "",
        joinerAction: StringJoiner.() -> Unit
): String = StringJoiner(delimiter, prefix, suffix).apply(joinerAction).toString()