scala / collection-strawman

Implementation of the new Scala 2.13 Collections
Apache License 2.0
200 stars 72 forks source link

Mutable sets and maps cannot drop elements with `flatMapInPlace` #509

Closed Ichoran closed 6 years ago

Ichoran commented 6 years ago
scala> val m = strawman.collection.mutable.HashSet(1)
m: strawman.collection.mutable.HashSet[Int] = HashSet(1)

scala> val s = strawman.collection.mutable.HashSet.empty[Int]
s: strawman.collection.mutable.HashSet[Int] = HashSet()

scala> m.flatMapInPlace(_ => s)
res0: m.type = HashSet(1)

and also

scala> val m = strawman.collection.mutable.HashSet(1)
m: strawman.collection.mutable.HashSet[Int] = HashSet(1)

scala> m.flatMapInPlace(i => strawman.collection.mutable.HashSet(i+1))
res1: m.type = HashSet(1, 2)
wibisono commented 6 years ago

@Ichoran I proposed a solution to this since the original implementation seems to never add any element to the toRemove variable that supposed to be used to drop elements.