user3663882 user3663882 - 1 year ago 55
Scala Question

Leaving parenthesis in method call

I thought in Scala we can leave paratnehsis when calling methods. I tried to do this, but compiler complains:

object Objd {
def m1(s: String) = {

def m2(s : Stirng) = {
.append("Another string")
.append(m1 s) //compile error. Not applicable to String

Why isn't it possible in such a case?

Answer Source

You can't do it in general. The rule is that

expr m1 arg1 m2 arg2 ...



In this case you don't have a start to the chain. You could write append(this m1 s).