I have a mutable scala Set:
val valueSet = scala.collection.mutable.Set[Int](0, 1, 2)
when I perform
valueSet -= 1
the result is Set(0,2)
But when I perform same thing inside a loop or map:
Range(0, 10).map(entry => valueSet -= 1)
valueSet
res130: scala.collection.mutable.Set[Int] = Set(0, 1, 2)
The content of valueSet remain: Set(0, 1, 2).
I need to run a loop and based on some condition, remove elements from the Set until either the loop ends or Set becomes empty. I tried printing the valueSet inside the loop and it is working correctly but when the loop ends the valueSet comes back to the original set.
Using immutable version is going to seriously affect the performance of the code that's why I am using mutable version.
Please help!
EDIT: I am using spark-shell REPL. (spark 1.6.1)
I tried several things more and figured out that if I am performing loop or map on and RDD then it doesn't work. But for collections that are non distributed, It works. I am guessing this has something to do with the fact that it is a transformation function on RDD and doesn't perform any action. But that is just my guess.