I have the following code:
val ls = List(0, -1, 2, -2)
var removeNegative = List[Int]()
def removeNegative(ls: List[Int]): Int = ls match {
case Nil => 0
case l::for(ls <- ls){
var removeNegative = List[Int]()
if(ls >= 0){
removeNegative = removeNegative :+ ls
}
}
return removeNegative
}
println(removeNegative(ls)
and I used the code in the function body as a standalone and it works, however I have had to add it into a function and I get the following errors:
ScalaFiddle.scala:7: error: illegal start of simple pattern
case l::for(ls <- ls){
^
ScalaFiddle.scala:16: error: '=>' expected but '}' found.
}
^
What have I done wrong here?