I was trying to figure out if function literal could have implicit parameters.
I found out in the post below that Function literal can not, by virtue of being FunctionN Object which do not have implicit parameter.
Scala Functional Literals with Implicits
However the answer contains the folloing as a trick
val sum2 = (a: Int) => {implicit b: Int => a + b}
I try to play around with it, but i am not really sure as to why it does compile and what exactly the construct implicit b: Int => a + b
stand for.
I try for instance
val sum2 = (a: Int) => {(implicit b: Int) => a + b}
or
val sum2 = (a: Int) => {implicit (b: Int) => a + b}
Both do not compile. My assumption in both case was that we are returning a function literal in implicit b: Int => a + b
. If so why the constructs above do not work. And why however the following construct works:
val sum2 = (e:Int) => { (f:Int) => e + f}
Can someone help me understand what is going on here ? I find it rather strange and incomprehensible.