MutableList missing -= and --= because it does not extend the Shrinkable . Various motivations for this can be found here.
MutableList has diff , filter and other methods that can help you if you are in a situation where reassigning a variable (or creating a new variable) can be an option, and performance isn 't paramount:
var mylist = MutableList(1, 2, 3) mylist = mylist diff Seq(1) val myNewList = mylist.filter(_ != 2) val indexFiltered = mylist.zipWithIndex.collect { case (el, ind) if ind != 1 => el }
You can often use a ListBuffer instead of a MutableList , which unlocks the necessary methods -= and --= :
val mylist = ListBuffer(1, 2, 3) mylist -= 1 //mylist is now ListBuffer(2, 3) mylist --= Seq(2, 3) //mylist is now empty
source share