title: Kotlin: Update Immutable List Element
body: <p>Kotlin beginner here. How do I take a list and without mutating it, create a second (immutable) list with one updated element at a specific index?</p>
  
  <p>I'm thinking of two ways, both of which seem like they may incur performance hits, mutate the underlying object, or both.</p>
  
  <pre><code>data class Player(val name: String, val score: Int = 0)
  
  val players: List&lt;Player&gt; = ...
  
  // Do I do this?
  val updatedPlayers1 = players.mapIndexed { i, player -&gt;
      if (i == 2) player.copy(score = 100)
      else player
  }
  
  // Or this?
  val updatedPlayer = players[2].copy(score = 100)
  val mutable = players.toMutableList()
  mutable.set(2, updatedPlayer)
  val updatedPlayers2 = mutable.toList()
  </code></pre>
  
  <p>If there is no performant way to do this, is there a more appropriate data structure in the Kotlin stdlib or other library? Kotlin doesn't seem to have vectors.</p>