The following code results in a StackOverflowError on the last line.
object StackTest extends App{
@tailrec def incrementValues(acc: Map[String, Int], in
mapValues
is known to be a trap, as it indeed creates only a wrapping view function instead of eagerly producing a new collection. Therefore, in your example you create a data structure of nesting level 10,000.
You can use the regular map
method:
acc.map(tup => (tup._1, tup._2 + 1))
or
acc.map { case (key, value) => (key, value + 1) }