Here's my code.
def f(x: Int) = x
val a = List(List(1), List(2, 2))
val b = a map { f(_.length) } // error
val c = a map { item => f(item.length) } // no error
Error occurs when compute b, it seems like the compiler expands the code in the following way:
val b = a map { f(x => x.length) } // absolutely wrong
That's why there's an error. And the correct expandation is something similar to what I do when compute c. However, how can compiler expand a function for f when function f doesn't expect a function?
For me, this expandation doesn't make any sense. Can anyone explain this behavior? Thanks!