1

I am writing a MapReduce job in Scalding and having difficulties compiling code that looks perfectly legitimate to me.

val persistenceBins = List[Int](1000 * 60 * 60, 2 * 1000 * 60 * 60, 4 * 1000 * 60 * 60)
val persistenceValues = persistenceBins.map(bin: Int => (bin, getPersistenceValues(connections, bin)) )

connections is RichPipe. getPersistenceValues is defined in the same class as the above code, as:

def getPersistenceValues(connections: RichPipe, binSize: Int): RichPipe = { ... }

I keep getting errors of the kind:

Error:(45, 87) ')' expected but '(' found.
val persistenceValues = persistenceBins.map(bin: Int => (bin, getPersistenceValues(connections, bin)) )
                                                                                  ^
Error:(45, 107) ';' expected but ')' found.
val persistenceValues = persistenceBins.map(bin: Int => (bin, getPersistenceValues(connections, bin)) )
                                                                                                      ^

I can't figure out what's going on. The errors look meaningless to me. What am I doing wrong?

Savage Reader
  • 387
  • 1
  • 4
  • 16

1 Answers1

4

In your case you cannot skip parentheses. This code should help you understand what is wrong.

scala> val persistenceBins = List[Int](1000 * 60 * 60, 2 * 1000 * 60 * 60, 4 * 1000 * 60 * 60)
persistenceBins: List[Int] = List(3600000, 7200000, 14400000)

scala> val persistenceValues = persistenceBins.map((bin: Int) => (bin, 0))
persistenceValues: List[(Int, Int)] = List((3600000,0), (7200000,0), (14400000,0))
  • Parenthesis around (bin: Int) fixed it. I can't believe I spent more than an hour trying to figure this out. Why did this happen? I have never ever seen parentheses used like this in a Scala book and no mention of it whatsoever. Thank you) – Savage Reader Jul 17 '14 at 16:25
  • @SavageReader You can skip parenthesis only if your lambda function has got one argument without declared type. In other case you have to remember about parenthesis. –  Jul 17 '14 at 16:37