Tuple with meaningful name - syntax question

I have a scala.List[(String, Double)] of tuple

I want to iterate it and refer to the value into my tuple with meaningful variable name, and not with _tuple.1 or _tuple.2

Currently, I was only able to write and compile with this syntax:

events.foreach( event => {
val (key, value) = event;
_println("key = " + key + ", value = " + value) _
}
)

But I would like to write it in a more compacted way , like this:
events.foreach( (key, value) => println("key = " + key + ", value = " + value) )

What do I miss? Is it possible?

In scala-3 you will be able to do that, in scala-2.x you’ll need to decompose like this:

events.foreach{case(key, value) => println(s"key: $key, value: $value")}

1 Like

Thanks. Much more aesthetic,
It works !!!