I was told that in Scala the return keyword was optional, I can write it or not (as for ;), no matter for the compiler
Please have a look at the following code:
case class Data(x:Int)
def test(data: List[Data]): List[Data] = {
val newdata: List[Data] = data
.map(d => {
val newdx = d.x * 2
return Data(newdx)
})
return newdata
}
It doesn't compile, because of the return statement.
Putting the same logic, also with return, in the main method, actually compile and works.
So, what is the semantic of return?