inline fun <T : MutableCollection<A>, A> T.mutateAllIndexed(transform: (index: Int, value: A) -> A): T

Applies transform to each element in the collection with the current item index, reusing the same structure to keep them.

The mutable equivalent to Collection.mapIndexed.

val p = Person(name = "John", job = Job("Developer", listOf("Kotlin", "Training")))
val newP = p.copy { // mutates the job.teams collection in-place
job.teams.mutateAllIndexed { i, team -> "${i + 1}." + team }

Note: this function removes in-place only if A is a MutableList, otherwise it clears the collection and re-adds the values.