Michael de Kaste
12/16/2021, 6:29 AMval packetVersion = stringbuilder.removeRange(0..2).toLong(2)
I guessed wrong this morning 😉elizarov
12/16/2021, 6:44 AMsubstring
?Michael de Kaste
12/16/2021, 6:51 AMremoveRange(0..2)
on a stringbuilder, removes those elements from that stringbuilder and then returns them.
instead, removeRange on a stringbuilder creates a whole new stringbuilder with everything but the chars at that range.elizarov
12/16/2021, 6:52 AMMichael de Kaste
12/16/2021, 6:52 AMMichael de Kaste
12/16/2021, 6:53 AMremoveFirst
-esque functions of mutable collections and thought removeRange
worked the same, since stringbuilder is a mutablestringMichael de Kaste
12/16/2021, 6:56 AMremoveAtRange
? 👀elizarov
12/16/2021, 7:04 AMremoveRange
. Moreover, there’s a whole family of those extensions on `CharSequence`: removePrefix
, removeSuffix
, removeSurrounding
that return a new CharSequence
just like removeRange
, which makes them confusing when applied to StringBuilder
. because you might expect them to work similarly to `removeFirst`/`removeLast`/`removeAll`/etc on mutable lists.ephemient
12/16/2021, 10:22 AMMichael de Kaste
12/16/2021, 10:31 AMexcludeRange
excludePrefix
, etc. and then rewrite the removes, but that seems like hindsight.
but removeAtRange(...)
doesn't exist on any mutable collection, which could technically still be added for all of themMichael de Kaste
12/16/2021, 10:32 AMremoveInRange
if that sounds betterJacob
12/16/2021, 3:58 PMremoveRange!
😛