I have a list of strings, like
val myList = List("apple", "orange", "pear")
I would like to transform it to a string like "1) apple 2) orange 3) pear". I could write a for loop, but I think that in Scala there should be an one-liner for things like this. The best one-liner I could come up with was
val myString = myList.map(s => "1) " + s).mkString(" ")
But this results in "1) apple 1) orange 1) pear". How can increment a value while mapping a list?