Ellen Spertus
01/30/2020, 5:55 PM// 1
regexBuilder.append(
alts.split("|")
.map { it.trim() }
.map { if (it.isEmpty()) "" else " $it"}
.joinToString(prefix = "(?:", separator = "|", postfix = ")"))
or
// 2
regexBuilder.append(
alts.split("|")
.map { it.trim() }.joinToString(
prefix = "(?:",
separator = "|",
postfix = ")"
) { if (it.isEmpty()) "" else " $it" })
diesieben07
01/30/2020, 6:09 PMalts.split("|")
.map { it.trim() }
.joinTo(regexBuilder, prefix = "(?:", separator = "|", postfix = ")") {
if (it.isEmpty()) "" else " $it"
}
diesieben07
01/30/2020, 6:11 PMalts.split("|")
.map { it.trim() }
.filter { it.isNotEmpty() }
.joinTo(regexBuilder, prefix = "(?:", separator = "|", postfix = ")")
Ellen Spertus
01/30/2020, 6:12 PMdiesieben07
01/30/2020, 6:12 PMEllen Spertus
01/30/2020, 6:13 PMEllen Spertus
01/30/2020, 6:13 PMEllen Spertus
01/30/2020, 6:14 PMString
, are joinTo
and joinToString
equivalent?diesieben07
01/30/2020, 6:14 PMdiesieben07
01/30/2020, 6:15 PMjoinTo
works on Appendable
, like StringBuilder
diesieben07
01/30/2020, 6:15 PMString
diesieben07
01/30/2020, 6:16 PMfoo.append(thing.joinToString()
and thing.joinTo(foo)
are the sameEllen Spertus
01/30/2020, 6:16 PMEllen Spertus
01/30/2020, 6:40 PMjoinTo
. My final code will be so elegant that it will go ballroom dancing. 💃 🕺