I've just written the following code, and I'm not ...
# getting-started
p
I've just written the following code, and I'm not proud of it. It's about as non-functional as you can get! Can anyone give any pointers to improvements ? I obviously want to get away from mutable lists, and vars for a starter. Please be gentle 😉 // in this case the string is a sequence of words, no longer than 3 chars long, separated by spaces. // the function splits the string into a list of strings, each no more than 67 chars long private val String.chunky: List<String> get() { val list = mutableListOf<String>() var line = "" var data = this.split(" ") data.forEach { line = "$line$it " if (line.length >= 67) { list.add(line.trim()) line = "" } } list.add(line.trim()) return list }