What would be even faster is to do this:
fun <T> List<T>.update(index: Int, item: T): List<T> = toMutableList().apply { this[index] = item) }
since it’ll just do one array copy under the hood and then it’ll replace that one element in the array.