1

Note: A detailed answer to the more general problem is in Stack Overflow question What are the precise rules for when you can omit parenthesis, dots, braces, = (functions), etc.?.

The following works:

scala> List(1,2,3) filter (_ > 1) reduceLeft(_ + _)
res65: Int = 5

And also the following:

scala> List(1,2,3).filter(_ > 1).foldLeft(0)(_ + _)
res67: Int = 5

But not this sytax:

scala> List(1,2,3) filter (_ > 1) foldLeft(0)(_ + _)
<console>:10: error: 0 of type Int(0) does not take parameters
       List(1,2,3) filter (_ > 1) foldLeft(0)(_ + _)
                                        ^

What is a suggested fix?

Community
  • 1
  • 1
ron
  • 9,262
  • 4
  • 40
  • 73

2 Answers2

7

This topic is well described in Stack Overflow question What are the precise rules for when you can omit parenthesis, dots, braces, = (functions), etc.?.

Curried functions seems to be little bit harder than methods with one parameter. To omit the dot, curried functions need to use parenthesis outside the infix call.

As Marimuthu Madasamy mentioned, this works (the object (List), the method (foldLeft) and its first parameter (0) are in parenthesis):

(List(1,2,3) filter (_ > 1) foldLeft 0) (_ + _)
Community
  • 1
  • 1
Steve
  • 18,660
  • 4
  • 34
  • 27
4

This works:

(List(1,2,3) filter (_ > 1) foldLeft 0) (_ + _)
Marimuthu Madasamy
  • 13,126
  • 4
  • 30
  • 52