Skip to content

Commit 59f1fec

Browse files
committed
[scala/scala#11017] Various Map.WithDefault classes expose the more specific WithDefault class as return type of concat method
1 parent d07cf7e commit 59f1fec

File tree

5 files changed

+13
-4
lines changed

5 files changed

+13
-4
lines changed

library/src/scala/collection/IterableOnce.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import scala.language.{higherKinds, implicitConversions}
55
import scala.annotation.unchecked.uncheckedVariance
66
import scala.math.{Numeric, Ordering}
77
import scala.reflect.ClassTag
8-
import java.lang.{StringBuilder => JStringBuilder}
98
import scala.collection.mutable.StringBuilder
109

1110
/**

library/src/scala/collection/immutable/Map.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ object Map extends MapFactory[Map] {
153153

154154
override def mapFactory: MapFactory[Map] = underlying.mapFactory
155155

156+
override def concat [V2 >: V](xs: collection.Iterable[(K, V2)]): WithDefault[K, V2] =
157+
new WithDefault(underlying.concat(xs), defaultValue)
158+
156159
def remove(key: K): WithDefault[K, V] = new WithDefault[K, V](underlying.remove(key), defaultValue)
157160

158161
def updated[V1 >: V](key: K, value: V1): WithDefault[K, V1] =

library/src/scala/collection/immutable/SortedMap.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,10 @@ object SortedMap extends SortedMapFactory.Delegate[SortedMap](TreeMap) {
9696
override def updated[V1 >: V](key: K, value: V1): WithDefault[K, V1] =
9797
new WithDefault[K, V1](underlying.updated(key, value), defaultValue)
9898

99-
override def remove(key: K): WithDefault[K, V] =
100-
new WithDefault[K, V](underlying.remove(key), defaultValue)
99+
override def concat [V2 >: V](xs: collection.Iterable[(K, V2)]): WithDefault[K, V2] =
100+
new WithDefault( underlying.concat(xs) , defaultValue)
101+
102+
override def remove(key: K): WithDefault[K, V] = new WithDefault[K, V](underlying.remove(key), defaultValue)
101103

102104
override def empty: WithDefault[K, V] = new WithDefault[K, V](underlying.empty, defaultValue)
103105

library/src/scala/collection/mutable/Map.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package scala
22
package collection
33
package mutable
44

5-
import scala.collection.MapFactory
65
import scala.language.higherKinds
76

87
/** Base type of mutable Maps */
@@ -187,6 +186,9 @@ object Map extends MapFactory.Delegate[Map](HashMap) {
187186

188187
def addOne(elem: (K, V)): WithDefault.this.type = { underlying.addOne(elem); this }
189188

189+
override def concat[V2 >: V](suffix: collection.Iterable[(K, V2)]): WithDefault[K, V2] =
190+
underlying.concat(suffix).withDefault(defaultValue)
191+
190192
override def empty: WithDefault[K, V] = new WithDefault[K, V](underlying.empty, defaultValue)
191193

192194
override protected def fromSpecificIterable(coll: scala.collection.Iterable[(K, V)]): WithDefault[K, V] =

library/src/scala/collection/mutable/SortedMap.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ object SortedMap extends SortedMapFactory.Delegate[SortedMap](TreeMap) {
7373

7474
override def empty: WithDefault[K, V] = new WithDefault[K, V](underlying.empty, defaultValue)
7575

76+
override def concat[V2 >: V](suffix: collection.Iterable[(K, V2)]): WithDefault[K, V2] =
77+
underlying.concat(suffix).withDefault(defaultValue)
78+
7679
override protected def fromSpecificIterable(coll: scala.collection.Iterable[(K, V)]): WithDefault[K, V] =
7780
new WithDefault[K, V](sortedMapFactory.from(coll), defaultValue)
7881

0 commit comments

Comments
 (0)