I have such a strange situation that I do not understand. I read the book Scala Programming, chap. nine.
Say I have a curric function:
def withThis(n:Int)(op:Int=>Unit){ println("Before") op(n); println("After") }
When I call it with one argument inside the special curly syntax, it works as expected:
withThis(5){ (x) => {println("Hello!"); println(x); } }
However, if I put two operators, I get something strange:
withThis(5){ println("Hello!") println(_) }
How come "Hello!" is printed before "Before" and then "5" is printed inside? I've gone crazy?
drozzy
source share