I’m taking my first interesting steps (non-hello-world level) with Scala (2.9.1) and I’m stuck trying to understand a very uninformative error message.
It goes much like this:
error: type mismatch;
found : (Int, Array[InputEntry]) => (Int, Double)
required: (Int, Array[InputEntry]) => ?
entries.groupBy(grouper).map((k: Int, ies: Array[InputEntry]) => (k, doMyStuff(ies)))
As you can guess process in this snippet is supposed to be where some processing goes on, and it’s actually a well defined function with signature Array[InputEntry] => Double.
Grouper’s signature, instead, is Array[InputEntry] => Int.
I’ve tried to extract a function and replace the lambda but it was useless, and I’m stuck trying to understand the question mark in the error…
Any ideas?
Edit: I should clarify that InputEntry is a class I’ve defined, but for the sake of this example it seems to me like it’s hardly relevant.
This looks like the problem:
You need to use a case statement to unapply the params and assign them to local variables. You also need to use {} instead of () because it is an anonymous function now.
Here’s a more simple example.
If you don’t want to use a case statement, you have to keep the tuple as a single variable.