Can I reduce the loop inside my method with map or is there a shorter implementation of this code that's dropping elements in sequence?
// Method that drops one element in sequence
def drop_Val_In_List[String](ls: Seq[String], value: String): Seq[String] = {
val index = ls.indexOf(value) //index is -1 if there is no matc
if (index < 0) {
ls
} else if (index == 0) {
ls.tail
} else {
// splitAt keeps the matching element in the second group
val (a, b) = ls.splitAt(index)
a ++ b.tail
}
}
val KeepCols = Seq("id", "type", "month", "car", "road")
// Generalization of the above method to drop multiple elements
def drop_Val_List_In_List[String](ls: Seq[String], in_ls: Seq[String]): Seq[String] = {
var tmp_ = ls
//println(tmp.getClass)
for(x <- in_ls ){ // should work without var x
tmp_ = drop_Val_In_List(tmp_, x)
}
tmp_;
}
val tmp = drop_Val_List_In_List(KeepCols, List("id", "type", "month"))
```
drop_Val_In_List()i.e.:type mismatch; found : java.lang.String; required: String(in method drop_Val_List_In_List)\$\endgroup\$