Reputation: 1682
I have the following spark code snippet .
But get the following error:
:8: error: missing parameter type.
which happens here:
val index:Int= col1(i) ; tokened +=splitted(index) + " " ; } }
^
I can't work out where it steps from as it seems like i've specified all properties. I also need to return the string so for the method to be string => string (currently it's string -> unit) This is my first time ever coding in scala so apologies if this is a stupid question
line => { var col1:Array[Int] = Array(1,2) ; var tokened:String = "" ;
var splitted:Array[String]=line.split(" ") ;
for (i<- 0 to col1.length) {
val index:Int= col1(i);
tokened +=splitted(index) + " " ;
}
}
Upvotes: 1
Views: 570
Reputation: 12852
I guess this is what you need:
(line: String) => { /* Previously missing type annotation */
var col1:Array[Int] = Array(1,2)
var tokened:String = ""
var splitted:Array[String]=line.split(" ")
for (i<- 0 to col1.length) {
val index:Int= col1(i)
tokened += splitted(index) + " "
}
tokened /* Return value */
}
In order to make the function type explicit, you could store the anonymous function in a function-typed variable:
val f: (String => String) = line => { ... }
Upvotes: 1