summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@typesafe.com>2015-02-18 11:26:05 -0800
committerAdriaan Moors <adriaan.moors@typesafe.com>2015-02-18 11:26:05 -0800
commite6a8b64c5c6015f2b1c49d4e8bba00ceb9c6fbd8 (patch)
treeaeb1cd1c117ca0ef0391f518fcbb7dba548b96f0
parentea17de17dd8fddb509fe9bb3ce1d126cd9955abd (diff)
parentd95269ef2c7f6a8cdbbf853edfddf625adde008c (diff)
downloadscala-e6a8b64c5c6015f2b1c49d4e8bba00ceb9c6fbd8.tar.gz
scala-e6a8b64c5c6015f2b1c49d4e8bba00ceb9c6fbd8.tar.bz2
scala-e6a8b64c5c6015f2b1c49d4e8bba00ceb9c6fbd8.zip
Merge pull request #4299 from michaelpigg/si-7660
SI-7660: Document behaviour of Set#++ for duplicate elements
-rw-r--r--src/library/scala/collection/SetLike.scala28
1 files changed, 21 insertions, 7 deletions
diff --git a/src/library/scala/collection/SetLike.scala b/src/library/scala/collection/SetLike.scala
index 3e549f72cd..c98ab6ecb1 100644
--- a/src/library/scala/collection/SetLike.scala
+++ b/src/library/scala/collection/SetLike.scala
@@ -107,22 +107,36 @@ self =>
*/
def + (elem: A): This
- /** Creates a new $coll with additional elements.
+ /** Creates a new $coll with additional elements, omitting duplicates.
*
- * This method takes two or more elements to be added. Another overloaded
- * variant of this method handles the case where a single element is added.
+ * This method takes two or more elements to be added. Elements that already exist in the $coll will
+ * not be added. Another overloaded variant of this method handles the case where a single element is added.
+ *
+ * Example:
+ * {{{
+ * scala> val a = Set(1, 3) + 2 + 3
+ * a: scala.collection.immutable.Set[Int] = Set(1, 3, 2)
+ * }}}
*
* @param elem1 the first element to add.
* @param elem2 the second element to add.
* @param elems the remaining elements to add.
- * @return a new $coll with the given elements added.
+ * @return a new $coll with the given elements added, omitting duplicates.
*/
def + (elem1: A, elem2: A, elems: A*): This = this + elem1 + elem2 ++ elems
- /** Creates a new $coll by adding all elements contained in another collection to this $coll.
+ /** Creates a new $coll by adding all elements contained in another collection to this $coll, omitting duplicates.
+ *
+ * This method takes a collection of elements and adds all elements, omitting duplicates, into $coll.
+ *
+ * Example:
+ * {{{
+ * scala> val a = Set(1, 2) ++ Set(2, "a")
+ * a: scala.collection.immutable.Set[Any] = Set(1, 2, a)
+ * }}}
*
- * @param elems the collection containing the added elements.
- * @return a new $coll with the given elements added.
+ * @param elems the collection containing the elements to add.
+ * @return a new $coll with the given elements added, omitting duplicates.
*/
def ++ (elems: GenTraversableOnce[A]): This = (repr /: elems.seq)(_ + _)