n.to...">

Cannot "compose" both method and function

I define a method and a function:

def print(str:String) = println
val intToString = (n:Int) => n.toString

      

Now I want to create them.

My problem is why neither one nor the other:

print(_) compose intToString
print(_:String) compose intToString

      

compiles?

But:

(print(_)) compose intToString
(print _ ) compose intToString

      

compiles?

+3


source to share


1 answer


I think,

print(_) compose intToString

      

desugars to

x => (print(x) compose intToString)

      



then

(print(_)) compose intToString

      

desugars to

(x => print(x)) compose intToString

      

+11


source







All Articles