Updating a tuple?

Firstly, I would recommend always defaulting to immutable references (i.e., use “val” instead of “var” unless you have a good reason for it).

Secondly, you say you want to increment only a single tuple, but your code is making the change for a set of values.

Depending on your desired performance characteristics, one approach would be to use the “map” higher-order function:

val myList = List((“J”, 10), (“D”, 60), (“M”, 20))

val tempSet = Set(“J”, “D”, “M”)

val updatedList = myList.map(x => if(tempSet.contains(x._1)) (x._1, x._2 +1) else x)

There are many ways to approach this problem, and this one is straightforward, but not the most performant; however, it’s good enough for many cases.

Regards,

Will