trySwap

fun <T : Any> MutableList<T>.trySwap(index1: Int, index2: Int): MutableList<T>

Swaps values index1 with index2 in place. Returns the original collection if either index1 or index2 are not resent