let's consider:
def foo: Int = {
val sumR: List[Int] => Int = _.foldLeft(0)((n, m) => return n + m)
sumR(List(1,2,3)) + sumR(List(4,5,6))
}
scala> foo
res4: Int = 1
Why first part of sumR(List(1,2,3)) + sumR(List(4,5,6))
expression is treated better? After all, return
should lead to returning from sumR
. So, why the result is not equal to 1+4
?