Skip to content

Commit 31db427

Browse files
authored
Merge pull request scala#5265 from szeiger/issue/6947
SI-6947 Better type parameter names for Map classes
2 parents d26b384 + 7e933d5 commit 31db427

File tree

9 files changed

+247
-248
lines changed

9 files changed

+247
-248
lines changed

src/library/scala/collection/GenMap.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@ import generic._
1818
* @author Aleksandar Prokopec
1919
* @since 2.9
2020
*/
21-
trait GenMap[A, +B]
22-
extends GenMapLike[A, B, GenMap[A, B]]
23-
with GenIterable[(A, B)]
21+
trait GenMap[K, +V]
22+
extends GenMapLike[K, V, GenMap[K, V]]
23+
with GenIterable[(K, V)]
2424
{
25-
def seq: Map[A, B]
25+
def seq: Map[K, V]
2626

27-
def updated [B1 >: B](key: A, value: B1): GenMap[A, B1]
27+
def updated [V1 >: V](key: K, value: V1): GenMap[K, V1]
2828
}
2929

3030
object GenMap extends GenMapFactory[GenMap] {
31-
def empty[A, B]: immutable.Map[A, B] = immutable.Map.empty
31+
def empty[K, V]: immutable.Map[K, V] = immutable.Map.empty
3232

3333
/** $mapCanBuildFromInfo */
34-
implicit def canBuildFrom[A, B]: CanBuildFrom[Coll, (A, B), GenMap[A, B]] = new MapCanBuildFrom[A, B]
34+
implicit def canBuildFrom[K, V]: CanBuildFrom[Coll, (K, V), GenMap[K, V]] = new MapCanBuildFrom[K, V]
3535
}

src/library/scala/collection/GenMapLike.scala

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ package collection
2222
* A map is a collection of bindings from keys to values, where there are
2323
* no duplicate keys.
2424
*/
25-
trait GenMapLike[A, +B, +Repr] extends GenIterableLike[(A, B), Repr] with Equals with Parallelizable[(A, B), parallel.ParMap[A, B]] {
26-
def default(key: A): B
27-
def get(key: A): Option[B]
28-
def apply(key: A): B
29-
def seq: Map[A, B]
30-
def +[B1 >: B](kv: (A, B1)): GenMap[A, B1]
31-
def - (key: A): Repr
25+
trait GenMapLike[K, +V, +Repr] extends GenIterableLike[(K, V), Repr] with Equals with Parallelizable[(K, V), parallel.ParMap[K, V]] {
26+
def default(key: K): V
27+
def get(key: K): Option[V]
28+
def apply(key: K): V
29+
def seq: Map[K, V]
30+
def +[V1 >: V](kv: (K, V1)): GenMap[K, V1]
31+
def - (key: K): Repr
3232

3333
// This hash code must be symmetric in the contents but ought not
3434
// collide trivially.
@@ -41,17 +41,17 @@ trait GenMapLike[A, +B, +Repr] extends GenIterableLike[(A, B), Repr] with Equals
4141
* @tparam B1 the result type of the default computation.
4242
* @return the value associated with `key` if it exists,
4343
* otherwise the result of the `default` computation.
44-
* @usecase def getOrElse(key: A, default: => B): B
44+
* @usecase def getOrElse(key: K, default: => V): V
4545
* @inheritdoc
4646
*/
47-
def getOrElse[B1 >: B](key: A, default: => B1): B1
47+
def getOrElse[V1 >: V](key: K, default: => V1): V1
4848

4949
/** Tests whether this map contains a binding for a key.
5050
*
5151
* @param key the key
5252
* @return `true` if there is a binding for `key` in this map, `false` otherwise.
5353
*/
54-
def contains(key: A): Boolean
54+
def contains(key: K): Boolean
5555

5656
/** Tests whether this map contains a binding for a key. This method,
5757
* which implements an abstract method of trait `PartialFunction`,
@@ -60,47 +60,47 @@ trait GenMapLike[A, +B, +Repr] extends GenIterableLike[(A, B), Repr] with Equals
6060
* @param key the key
6161
* @return `true` if there is a binding for `key` in this map, `false` otherwise.
6262
*/
63-
def isDefinedAt(key: A): Boolean
63+
def isDefinedAt(key: K): Boolean
6464

65-
def keySet: GenSet[A]
65+
def keySet: GenSet[K]
6666

6767
/** Collects all keys of this map in an iterable collection.
6868
*
6969
* @return the keys of this map as an iterable.
7070
*/
71-
def keys: GenIterable[A]
71+
def keys: GenIterable[K]
7272

7373
/** Collects all values of this map in an iterable collection.
7474
*
7575
* @return the values of this map as an iterable.
7676
*/
77-
def values: GenIterable[B]
77+
def values: GenIterable[V]
7878

7979
/** Creates an iterator for all keys.
8080
*
8181
* @return an iterator over all keys.
8282
*/
83-
def keysIterator: Iterator[A]
83+
def keysIterator: Iterator[K]
8484

8585
/** Creates an iterator for all values in this map.
8686
*
8787
* @return an iterator over all values that are associated with some key in this map.
8888
*/
89-
def valuesIterator: Iterator[B]
89+
def valuesIterator: Iterator[V]
9090

9191
/** Filters this map by retaining only keys satisfying a predicate.
9292
* @param p the predicate used to test keys
9393
* @return an immutable map consisting only of those key value pairs of this map where the key satisfies
9494
* the predicate `p`. The resulting map wraps the original map without copying any elements.
9595
*/
96-
def filterKeys(p: A => Boolean): GenMap[A, B]
96+
def filterKeys(p: K => Boolean): GenMap[K, V]
9797

9898
/** Transforms this map by applying a function to every retrieved value.
9999
* @param f the function used to transform values of this map.
100100
* @return a map view which maps every key of this map
101101
* to `f(this(key))`. The resulting map wraps the original map without copying any elements.
102102
*/
103-
def mapValues[C](f: B => C): GenMap[A, C]
103+
def mapValues[W](f: V => W): GenMap[K, W]
104104

105105
/** Compares two maps structurally; i.e., checks if all mappings
106106
* contained in this map are also contained in the other map,

src/library/scala/collection/Map.scala

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ package collection
1212
import generic._
1313

1414
/**
15-
* A map from keys of type `A` to values of type `B`.
15+
* A map from keys of type `K` to values of type `V`.
1616
*
1717
* $mapNote
1818
*
@@ -22,38 +22,38 @@ import generic._
2222
* '''Note:''' If your additions and mutations return the same kind of map as the map
2323
* you are defining, you should inherit from `MapLike` as well.
2424
*
25-
* @tparam A the type of the keys in this map.
26-
* @tparam B the type of the values associated with keys.
25+
* @tparam K the type of the keys in this map.
26+
* @tparam V the type of the values associated with keys.
2727
*
2828
* @since 1.0
2929
*/
30-
trait Map[A, +B] extends Iterable[(A, B)] with GenMap[A, B] with MapLike[A, B, Map[A, B]] {
31-
def empty: Map[A, B] = Map.empty
30+
trait Map[K, +V] extends Iterable[(K, V)] with GenMap[K, V] with MapLike[K, V, Map[K, V]] {
31+
def empty: Map[K, V] = Map.empty
3232

33-
override def seq: Map[A, B] = this
33+
override def seq: Map[K, V] = this
3434
}
3535

3636
/** $factoryInfo
3737
* @define Coll `Map`
3838
* @define coll map
3939
*/
4040
object Map extends MapFactory[Map] {
41-
def empty[A, B]: immutable.Map[A, B] = immutable.Map.empty
41+
def empty[K, V]: immutable.Map[K, V] = immutable.Map.empty
4242

4343
/** $mapCanBuildFromInfo */
44-
implicit def canBuildFrom[A, B]: CanBuildFrom[Coll, (A, B), Map[A, B]] = new MapCanBuildFrom[A, B]
44+
implicit def canBuildFrom[K, V]: CanBuildFrom[Coll, (K, V), Map[K, V]] = new MapCanBuildFrom[K, V]
4545

4646
/** An abstract shell used by { mutable, immutable }.Map but not by collection.Map
4747
* because of variance issues.
4848
*/
49-
abstract class WithDefault[A, +B](underlying: Map[A, B], d: A => B) extends AbstractMap[A, B] with Map[A, B] with Serializable {
49+
abstract class WithDefault[K, +V](underlying: Map[K, V], d: K => V) extends AbstractMap[K, V] with Map[K, V] with Serializable {
5050
override def size = underlying.size
51-
def get(key: A) = underlying.get(key) // removed in 2.9: orElse Some(default(key))
51+
def get(key: K) = underlying.get(key) // removed in 2.9: orElse Some(default(key))
5252
def iterator = underlying.iterator
53-
override def default(key: A): B = d(key)
53+
override def default(key: K): V = d(key)
5454
}
5555

5656
}
5757

5858
/** Explicit instantiation of the `Map` trait to reduce class file size in subclasses. */
59-
abstract class AbstractMap[A, +B] extends AbstractIterable[(A, B)] with Map[A, B]
59+
abstract class AbstractMap[K, +V] extends AbstractIterable[(K, V)] with Map[K, V]

0 commit comments

Comments
 (0)