I am new to Scala and am having problems with an example from Scala's book in action.
I use IntelliJ, but I also tried it as a script (REPL). The Scala compiler gives me the same error as IntelliJ. (I use Scala 2.10 as the book suggests).
Here is my code:
def parseArgs(args: Array[String]): Map[String, List[String]] = {
val command = args.head
val params = parseArgs(args)
val url = args.last
def nameValuePair(paramName: String) = {
def values(commaSeparatedValues: String) = commaSeparatedValues.split(",").toList
val index = args.indexOf(_ == paramName)
(paramName, if(index == -1) Nil else values(args(index + 1)))
}
Map(nameValuePair("-d"), nameValuePair("-h"))
}
The message I get:
C:\scala\projects\scripts\restclientscript.scala:12: error: missing parameter type for expanded function ((x$1) => x$1.$eq$eq(paramName))
val index = args.indexOf(_ == paramName)
^
one error found
This is exactly as shown in the book, but I cannot figure out how to make it work.
Also, the indexOf method actually finds the IndexOf in the book. But this method does not exist, the compiler tells me (and doc: http://www.scala-lang.org/api/2.10.3/index.html#scala.Array ).
Finally, IntelliJ will not accept the value inside the indexOf () method (highlighted in red, but compiles).
Any help would be appreciated! :)