You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
operator in SortedSet doesn't work as stated in Scaladoc:
"Creates a new set with an additional element, unless the element is already present."
It replaces existing element.
Same thing with ++.
Reproduced in 2.10.0-M4 and 2.9.1.
Example:
Welcome to Scala version 2.10.0-M4 (JavaHotSpot(TM) 64-BitServerVM, Java1.6.0_31).
Type in expressions to have them evaluated.
Type:help for more information.
scala>importscala.collection.immutable.SortedSetimportscala.collection.immutable.SortedSet
scala>classFoo(valname:String, valn:Int) {
|overridedefequals(obj: Any):Boolean= obj match { caseother: Foo=> name == other.name; case _ =>false }
|overridedefhashCode= name.##
|overridedeftoString="Foo("+ name +", "+ n +")"| }
defined classFoo
scala>implicitvalordering:Ordering[Foo] =Ordering.fromLessThan[Foo] { (a, b) => a.name.compareTo(b.name) <0 }
ordering:Ordering[Foo] = scala.math.Ordering$$anon$9@32370bf9
scala>SortedSet(newFoo("bar", 1)) +newFoo("bar", 2)
res0: scala.collection.immutable.SortedSet[Foo] =TreeSet(Foo(bar, 2))
Another example:
Welcome to Scala version 2.10.0-M4 (JavaHotSpot(TM) 64-BitServerVM, Java1.6.0_31).
Type in expressions to have them evaluated.
Type:help for more information.
scala>importscala.collection.immutable.TreeSetimportscala.collection.immutable.TreeSet
scala>importscala.collection.immutable.SortedSetimportscala.collection.immutable.SortedSet
scala>vals:SortedSet[String] =TreeSet()
s: scala.collection.immutable.SortedSet[String] =TreeSet()
scala> s +newString("foo")
res0: scala.collection.immutable.SortedSet[String] =TreeSet(foo)
scala> res0.head.hashCode
res1:Int=101574
scala>System.identityHashCode(res0.head)
res2:Int=1965496749
scala>System.identityHashCode(res0 +newString("foo"))
res3:Int=856318696
scala>System.identityHashCode(res0 +newString("foo"))
res4:Int=143836998
scala>System.identityHashCode((res0 +newString("foo")).head)
res5:Int=1652856443
The text was updated successfully, but these errors were encountered:
"Creates a new set with an additional element, unless the element is already present."
It replaces existing element.
Same thing with ++.
Reproduced in 2.10.0-M4 and 2.9.1.
Example:
Another example:
The text was updated successfully, but these errors were encountered: