```fun <T> List<T>.swap(index1: Int, i...
# getting-started
k
Copy code
fun <T> List<T>.swap(index1: Int, index2: Int): List<T> = toMutableList().also { it.swap(index1, index2) }

fun <T> MutableList<T>.swap(index1: Int, index2: Int) {
    val tmp = this[index1]
    this[index1] = this[index2]
    this[index2] = tmp
}