lunduniversity / introprog

Teaching material for "Introduction to Programming using Scala" at Lund University, LTH. http://cs.lth.se/pgk/
141 stars 173 forks source link

quickref: incorrect description for mutable set methods #639

Closed sadphi closed 2 years ago

sadphi commented 2 years ago

There is an incorrect description for the methods add and remove for mutable sets in the quickref, and can be found at page 7. The description currently says "Adds/removes x to xs and returns true if x was in xs, else false.", however this is only the case for the method remove. See the following REPL example (using Scala 3.1.3):

scala> import collection.mutable.Set as MSet

scala> val xs = MSet(1,2,3)
val xs: scala.collection.mutable.Set[Int] = HashSet(1, 2, 3)

scala> xs add 1
val res4: Boolean = false // should be true according to quickref

scala> xs add 4
val res7: Boolean = true // should be false according to quickref

scala> xs remove 1
val res9: Boolean = true

scala> xs remove 1
val res10: Boolean = false

The behaviour seems to be that the methods return true if the methods actually mutated the set. I suggest that the description is changed to "Adds/removes x to xs and returns true if xs was mutated, else false.", or something similar. I can create a pull request with this change if it sounds good.

bjornregnell commented 2 years ago

Good catch! Have you checked what the official api documentation says? And perhaps, if needed, also look at the implementation to check your assumptions and what to write in the quickref? (should be as short as possible and the proposed wordings eems fine if it aligns with doc/implementation)

sadphi commented 2 years ago

I've taken a look at the official api docs here, and at the implementations that are linked there, and the behaviour matches the assumption. I've created a pull request (#640) with the proposed change.

bjornregnell commented 2 years ago

Excellent! Many thanks!

bjornregnell commented 2 years ago

Fixed by #640