How does one define an anonymous function with call-by-name parameters in scala?
I tried the following:
val fun = (x: Boolean, y: =>Int) => if(x) y else 0
This works well with call-by-value y, but not with call-by-name. Why?
It can be done, but in a slightly different way: declare the type separately from the parameters:
val fun: (Boolean, => Int) => Int = (x, y) => if (x) y else 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With