In Scala 2.9.2
List(List(1,5,4),List(7,9,11)).flatten.map {i => println(i); identity(i) }.find { _ % 2 == 0 }
Prints:
1
5
4
7
9
11
Option[Int] = Some(4)
But
List(List(1,5,4),List(7,9,11)).flatten.map { println("."); identity(_) }.find { _ % 2 == 0 }
Prints
.
Option[Int] = Some(4)
I must admit, I'm slightly suprised by this behavior. Underscore does not seem to be merely a shorthand for the equivalent in-line function, but has other affects on the code. What is going on here?