I've a question about extensions, and how to mutat...
# announcements
n
I've a question about extensions, and how to mutate a string from one, what I've got so fat its
Copy code
fun String.consumeWhile(test: (String) -> Boolean): String {
    if (isEmpty()) return ""

    val chars = toCharArray().toMutableList()
    var result = ""
    var i = -1

    while (chars.isNotEmpty() && test(chars.first().toString())) {
        result += chars.removeAt(0)
        ++i
    }

    removeRange(0..i) // this line should remove the consumed characters, but seems that is not working as I expect

    return result
}
the usage should be
Copy code
val myString = "--test"
myString.consumeWhile({ it != "-" })
print(myString) // output: "--test" but I expect the output to be just "test"