Skip to content

Commit 1c137f5

Browse files
committed
Naming consistency
1 parent 11db480 commit 1c137f5

File tree

7 files changed

+36
-30
lines changed

7 files changed

+36
-30
lines changed
Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package strawman
22
package collection.immutable
33

4+
import strawman.collection.IterableMonoTransforms
5+
46
/** Base type of immutable Maps */
57
trait Map[K, +V]
68
extends collection.Map[K, V]
@@ -9,27 +11,19 @@ trait Map[K, +V]
911
/** Base trait of immutable Maps implementations */
1012
trait MapLike[K, +V, +C[X, +Y] <: Map[X, Y]]
1113
extends collection.MapLike[K, V, C]
12-
with MapOps[K, V, C]
14+
with MapMonoTransforms[K, V, C[K, V]]
1315
with Iterable[(K, V)]
1416

1517
/** Immutable Map operations returning a self-like Map */
16-
trait MapOps[K, +V, +C[X, +Y] <: Map[X, Y]] {
17-
18-
/**
19-
* Add a key/value pair to this map, returning a new map.
20-
*
21-
* @param kv the key/value pair.
22-
* @tparam V1 the type of the value in the key/value pair.
23-
* @return A new map with the new binding added to this map.
24-
*/
25-
def + [V1 >: V](kv: (K, V1)): C[K, V1]
18+
trait MapMonoTransforms[K, +V, +Repr <: Map[K, V]]
19+
extends IterableMonoTransforms[(K, V), Repr] {
2620

2721
/**
2822
* Removes a key from this map, returning a new map.
2923
*
3024
* @param key the key to be removed
3125
* @return a new map without a binding for ''key''
3226
*/
33-
def - (key: K): C[K, V]
27+
def - (key: K): Repr
3428

3529
}

src/main/scala/strawman/collection/immutable/Set.scala

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1-
package strawman.collection.immutable
1+
package strawman
2+
package collection.immutable
23

34
/** Base trait for immutable set collections */
45
trait Set[A]
5-
extends strawman.collection.Set[A]
6+
extends collection.Set[A]
67
with Iterable[A]
78
with SetLike[A, Set]
89

910
/** Base trait for immutable set operations */
1011
trait SetLike[A, +C[X] <: Set[X]]
11-
extends strawman.collection.SetLike[A, C]
12-
with SetOps[A, C[A]]
12+
extends collection.SetLike[A, C]
13+
with SetMonoTransforms[A, C[A]]
1314

14-
trait SetOps[A, +Repr] {
15+
/** Transformation operations returning a Set containing the same kind of
16+
* elements
17+
*/
18+
trait SetMonoTransforms[A, +Repr]
19+
extends collection.SetMonoTransforms[A, Repr] {
1520

1621
def + (elem: A): Repr
1722

src/main/scala/strawman/collection/immutable/SortedMap.scala

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package strawman
22
package collection.immutable
33

4-
import strawman.collection.{IterableMonoTransforms, IterablePolyTransforms, MapPolyTransforms, Sorted, SortedLike}
4+
import strawman.collection.{IterablePolyTransforms, MapPolyTransforms, Sorted, SortedLike}
55

66
import scala.annotation.unchecked.uncheckedVariance
77
import scala.Ordering
@@ -15,8 +15,7 @@ trait SortedMapLike[K, +V, +C[X, +Y] <: SortedMap[X, Y]]
1515
extends SortedLike[K, C[K, V]]
1616
with SortedMapPolyTransforms[K, V, C]
1717
with MapLike[K, V, Map] // Inherited Map operations can only return a `Map` because they don’t take an evidence `Ordering`
18-
with MapOps[K, V, C] // Operations that return the same collection type can return a `SortedMap`, though
19-
with IterableMonoTransforms[(K, V), C[K, V]] // Transformation operations that return the same collection type can return a `SortedMap`, though
18+
with MapMonoTransforms[K, V, C[K, V]] // Operations that return the same collection type can return a `SortedMap`, though
2019

2120
/** Polymorphic transformation methods for sorted Maps */
2221
trait SortedMapPolyTransforms[K, +V, +C[X, Y] <: Sorted[X]]
@@ -31,5 +30,14 @@ trait SortedMapPolyTransforms[K, +V, +C[X, Y] <: Sorted[X]]
3130
// And finally, we add new overloads taking an ordering
3231
def map[K2, V2](f: (K, V) => (K2, V2))(implicit ordering: Ordering[K2]): C[K2, V2]
3332

33+
/**
34+
* Add a key/value pair to this map, returning a new map.
35+
*
36+
* @param kv the key/value pair.
37+
* @tparam V1 the type of the value in the key/value pair.
38+
* @return A new map with the new binding added to this map.
39+
*/
40+
def + [V1 >: V](kv: (K, V1)): C[K, V1]
41+
3442
}
3543

src/main/scala/strawman/collection/immutable/SortedSet.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package strawman.collection.immutable
22

3-
import strawman.collection.{SetMonoTransforms, Sorted, SortedLike, SortedPolyTransforms}
3+
import strawman.collection.{Sorted, SortedLike, SortedPolyTransforms}
44

55
/** Base trait for sorted sets */
66
trait SortedSet[A]
@@ -12,5 +12,4 @@ trait SortedSetLike[A, +C[X] <: SortedSet[X]]
1212
extends SortedLike[A, C[A]]
1313
with SortedPolyTransforms[A, C]
1414
with SetLike[A, Set] // Inherited Set operations return a `Set`
15-
with SetOps[A, C[A]] // Override the return type of Set ops to return C[A]
16-
with SetMonoTransforms[A, C[A]]
15+
with SetMonoTransforms[A, C[A]] // Override the return type of Set ops to return C[A]

src/main/scala/strawman/collection/immutable/TreeMap.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ final class TreeMap[K, +V]
2222
// Members declared in collection.MapLike
2323
def get(key: K): Option[V] = ???
2424

25-
// Members declared in collection.immutable.MapLike
25+
// Members declared in collection.immutable.MapMonoTransforms
2626
def -(key: K): TreeMap[K,V] = ???
2727
def +[V1 >: V](kv: (K, V1)): TreeMap[K,V1] = ???
2828

src/main/scala/strawman/collection/immutable/TreeSet.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ final class TreeSet[A]()(implicit val ordering: Ordering[A])
2626
def & (that: strawman.collection.Set[A]): TreeSet[A] = ???
2727
def ++ (that: strawman.collection.Set[A]): TreeSet[A] = ???
2828

29+
// From immutable.SetMonoTransforms
30+
def +(elem: A): TreeSet[A] = ???
31+
def -(elem: A): TreeSet[A] = ???
32+
2933
// From SortedLike
3034
def range(from: A, until: A): TreeSet[A] = ???
3135

3236
// From SortedPolyTransforms
3337
def map[B](f: (A) => B)(implicit ordering: Ordering[B]): TreeSet[B] = ???
3438

35-
// From immutable.SetLike
36-
def +(elem: A): TreeSet[A] = ???
37-
def -(elem: A): TreeSet[A] = ???
38-
3939
}
4040

4141
object TreeSet extends OrderingGuidedFactories[TreeSet] {

src/test/scala/strawman/collection/test/Test.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ class StrawmanTest {
303303
}
304304

305305
def sortedSets(xs: immutable.SortedSet[Int]): Unit = {
306-
val xs1 = xs.map((x: Int) => x.toString)
306+
val xs1 = xs.map((x: Int) => x.toString) // TODO Remove type annotation when https://github.com/scala/scala/pull/5708 is published
307307
val xs2: immutable.SortedSet[String] = xs1
308308
}
309309

@@ -325,7 +325,7 @@ class StrawmanTest {
325325
val xs2: immutable.SortedMap[String, Int] = xs1
326326
val xs3 = xs.map(kv => kv._1)
327327
val xs4: immutable.Iterable[String] = xs3
328-
val xs5 = xs.map((k: String, v: Int) => (v, k))
328+
val xs5 = xs.map((k: String, v: Int) => (v, k)) // TODO Remove type annotation when https://github.com/scala/scala/pull/5708 is published
329329
val xs6: immutable.SortedMap[Int, String] = xs5
330330
class Foo
331331
// val xs7 = xs.map((k: String, v: Int) => (new Foo, v)) Error: No implicit Ordering defined for Foo

0 commit comments

Comments
 (0)