Philipp Mayer
12/07/2020, 9:08 PMvar label = when {
..someConditions.. -> "someString"
else -> ""
}
regexes.forEach {
label = label.replace(it.toRegex(), "").trim()
}
return label
I should maybe just step away from it for some time.. 😄
any hint is appreciated, thanks!ephemient
12/07/2020, 9:12 PMlabel = regexes.fold(label) { label, regex -> label.replace(regex, "") }
nanodeath
12/07/2020, 10:11 PMlist.forEach {
x = f(x)
}
is often best modeled as a fold/reduce-type thing.
only exception is probably if you're working with collections...List#add makes a copy each time, which can have atrocious performance, so gotta watch out for that.ephemient
12/07/2020, 11:34 PM.mapTo()
🙂Joel
12/08/2020, 12:50 AMnanodeath
12/08/2020, 12:52 AMnanodeath
12/08/2020, 12:52 AMJoel
12/08/2020, 12:52 AMList#add
performance issuenanodeath
12/08/2020, 12:52 AMnanodeath
12/08/2020, 12:53 AMmapTo
suggestionephemient
12/08/2020, 12:53 AMval result = list.fold(listOf()) { result, it -> result + it }
or val result = mutableListOf(); list.forEach { result.add(f(it)) }
ephemient
12/08/2020, 12:53 AMlist.mapTo(result) { f(it) }
ephemient
12/08/2020, 12:55 AM.map()
, but in general .mapTo()
has its uses tooJoel
12/08/2020, 12:56 AMArrayList#add
that it creates a new array under the hood each time?ephemient
12/08/2020, 1:26 AMPhilipp Mayer
12/08/2020, 8:22 AMMatteo Mirk
12/18/2020, 2:23 PM