Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't `compose` and method and a function

I define a method and a function:

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

Now I want to compose them.

My problem is, why neither:

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

compiles?

But:

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

compiles?

like image 818
Freewind Avatar asked Mar 03 '26 16:03

Freewind


1 Answers

I think

print(_) compose intToString

desugars to

x => (print(x) compose intToString)

whereas

(print(_)) compose intToString

desugars to

(x => print(x)) compose intToString
like image 193
Chris Martin Avatar answered Mar 06 '26 06:03

Chris Martin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!