Skip to content
This repository was archived by the owner on Dec 22, 2021. It is now read-only.

Commit 5e3ddde

Browse files
committed
Remove type members representing collection types
1 parent c5e101c commit 5e3ddde

File tree

4 files changed

+59
-129
lines changed

4 files changed

+59
-129
lines changed

collections-contrib/src/main/scala/strawman/collection/decorators/HasImmutableMapOps.scala

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@ package decorators
33

44
/**
55
* Type class witnessing that a collection representation type `Repr` has
6-
* a conversion to `immutable.MapOps[K, V, CC2, C]`, for some type `K`,
7-
* `V`, `CC2[_, _]` and `C`
6+
* a conversion to `immutable.MapOps[K, V, _, _]`.
7+
*
88
* @see [[scala.collection.decorators.HasIterableOps]]
99
*/
1010
trait HasImmutableMapOps[Repr] extends HasMapOps[Repr] {
1111

12-
type CC2[X, +Y] <: immutable.MapOps[X, Y, CC2, _]
13-
14-
type C <: immutable.MapOps[K, V, CC2, C]
12+
protected type CC2[X, +Y] <: immutable.MapOps[X, Y, CC2, _]
13+
protected type C <: immutable.MapOps[K, V, CC2, C]
1514

1615
/** A conversion from the representation type `Repr` to `immutable.MapOps[K, V, CC2, C]` */
1716
val conversion: Repr => immutable.MapOps[K, V, CC2, C]
@@ -20,32 +19,29 @@ trait HasImmutableMapOps[Repr] extends HasMapOps[Repr] {
2019

2120
object HasImmutableMapOps {
2221

22+
type SomeImmutableMapOps[K, +V] <: immutable.MapOps[K, V, SomeImmutableMapOps, SomeImmutableMapOps[K, V]]
23+
2324
/** A type alias for `HasImmutableMapOps` that moves type members to type parameters */
24-
type Aux[Repr, K0, V0, CC20[X, +Y] <: immutable.MapOps[X, Y, CC20, _], C0 <: immutable.MapOps[K0, V0, CC20, C0]] = HasImmutableMapOps[Repr] {
25-
type K = K0
26-
type V = V0
27-
type CC2[X, +Y] = CC20[X, Y]
28-
type C = C0
29-
}
25+
type Aux[Repr, K0, V0] = HasImmutableMapOps[Repr] { type K = K0; type V = V0 }
3026

3127
// 1. Map collections
32-
implicit def mapHasMapOps[CC20[X, +Y] <: immutable.MapOps[X, Y, CC20, CC20[X, Y]], K0, V0]: HasImmutableMapOps.Aux[CC20[K0, V0], K0, V0, CC20, CC20[K0, V0]] =
33-
new HasImmutableMapOps[CC20[K0, V0]] {
28+
implicit def mapHasMapOps[CC[X, +Y] <: immutable.MapOps[X, Y, CC, CC[X, Y]], K0, V0]: HasImmutableMapOps.Aux[CC[K0, V0], K0, V0] =
29+
new HasImmutableMapOps[CC[K0, V0]] {
3430
type K = K0
3531
type V = V0
36-
type CC2[X, +Y] = CC20[X, Y]
37-
type C = CC20[K, V]
38-
val conversion: CC20[K0, V0] => immutable.MapOps[K0, V0, CC20, CC20[K0, V0]] = c => c
32+
type CC2[X, +Y] = CC[X, Y]
33+
type C = CC[K, V]
34+
val conversion: CC[K0, V0] => immutable.MapOps[K0, V0, CC2, C] = c => c
3935
}
4036

4137
// 2. Sorted Map collections
42-
implicit def sortedMapHasMapOps[CC20[X, +Y] <: immutable.Map[X, Y] with immutable.SortedMapOps[X, Y, CC20, CC20[X, Y]], K0, V0]: HasImmutableMapOps.Aux[CC20[K0, V0], K0, V0, immutable.Map, CC20[K0, V0]] =
43-
new HasImmutableMapOps[CC20[K0, V0]] {
38+
implicit def sortedMapHasMapOps[CC[X, +Y] <: immutable.Map[X, Y] with immutable.SortedMapOps[X, Y, CC, CC[X, Y]], K0, V0]: HasImmutableMapOps.Aux[CC[K0, V0], K0, V0] =
39+
new HasImmutableMapOps[CC[K0, V0]] {
4440
type K = K0
4541
type V = V0
4642
type CC2[X, +Y] = immutable.Map[X, Y]
47-
type C = CC20[K, V]
48-
val conversion: CC20[K0, V0] => immutable.MapOps[K0, V0, immutable.Map, CC20[K0, V0]] = c => c
43+
type C = CC2[K, V]
44+
val conversion: CC[K0, V0] => immutable.MapOps[K0, V0, immutable.Map, CC[K0, V0]] = c => c
4945
}
5046

5147
}

collections-contrib/src/main/scala/strawman/collection/decorators/HasIterableOps.scala

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ package decorators
33

44
/**
55
* Type class witnessing that a collection representation type `Repr`
6-
* has elements of type `A` and has a conversion to `IterableOps[A, CC, C]`
7-
* for some types `CC[_]` and `C`.
6+
* has elements of type `A` and has a conversion to `IterableOps[A, _, _]`.
87
*
98
* This type enables simple enrichment of `Iterable`s with extension methods.
109
*
@@ -15,49 +14,33 @@ trait HasIterableOps[Repr] {
1514
/** The type of elements (e.g. `Int`) */
1615
type A
1716

18-
/** The type constructor returned by transformation operations that might change the element type (e.g. `List`) */
19-
type CC[_]
20-
21-
/** The type returned by transformation operations that keep the same type of elements (e.g. `List[Int]`) */
22-
type C
23-
24-
/** A conversion from the representation type `Repr` to `IterableOps[A, CC, C]` */
25-
val conversion: Repr => IterableOps[A, CC, C]
17+
/** A conversion from the representation type `Repr` to `IterableOps[A, _, _]` */
18+
val conversion: Repr => IterableOps[A, AnyConstr, _]
2619

2720
}
2821

2922
object HasIterableOps extends LowPriorityHasIterableOps {
3023

31-
implicit def iterableHasIterableOps[CC0[X] <: IterableOps[X, CC0, CC0[X]], A0]: HasIterableOps.Aux[CC0[A0], A0, CC0, CC0[A0]] =
32-
new HasIterableOps[CC0[A0]] {
33-
type A = A0
34-
type CC[X] = CC0[X]
35-
type C = CC0[A0]
36-
val conversion: CC0[A0] => IterableOps[A0, CC0, CC0[A0]] = c => c
37-
}
38-
39-
implicit def viewHasIterableOps[CC0[X] <: View[X], A0]: HasIterableOps.Aux[CC0[A0], A0, View, View[A0]] =
40-
new HasIterableOps[CC0[A0]] {
24+
implicit def iterableHasIterableOps[CC[X] <: IterableOps[X, AnyConstr, _], A0]: HasIterableOps.Aux[CC[A0], A0] =
25+
new HasIterableOps[CC[A0]] {
4126
type A = A0
42-
type CC[X] = View[X]
43-
type C = View[A0]
44-
val conversion: CC0[A0] => IterableOps[A0, View, View[A0]] = c => c
27+
val conversion: CC[A0] => IterableOps[A0, AnyConstr, _] = c => c
4528
}
4629

4730
}
4831

4932
trait LowPriorityHasIterableOps {
5033

51-
type Aux[Repr, A0, CC0[_], C0] = HasIterableOps[Repr] { type A = A0; type CC[X] = CC0[X]; type C = C0 }
34+
type Aux[Repr, A0] = HasIterableOps[Repr] { type A = A0 }
5235

5336
// Makes `HasSeqOps` instances visible in `HasIterableOps` companion
54-
implicit def hasSeqOpsHasIterableOps[Repr, A, CC[_], C](implicit
55-
hasSeqOps: HasSeqOps.Aux[Repr, A, CC, C]
56-
): HasIterableOps.Aux[Repr, A, CC, C] = hasSeqOps
37+
implicit def hasSeqOpsHasIterableOps[Repr, A](implicit
38+
hasSeqOps: HasSeqOps.Aux[Repr, A]
39+
): HasIterableOps.Aux[Repr, A] = hasSeqOps
5740

5841
// Makes `HasMapOps` instances visible in `HasIterableOps` companion
59-
implicit def hasMapOpsHasIterableOps[Repr, K0, V0, CC20[_, +_] <: IterableOps[_, AnyConstr, _], C0](implicit
60-
hasMapOps: HasMapOps.Aux[Repr, K0, V0, CC20, C0]
61-
): HasIterableOps.Aux[Repr, (K0, V0), Iterable, C0] = hasMapOps
42+
implicit def hasMapOpsHasIterableOps[Repr, K0, V0](implicit
43+
hasMapOps: HasMapOps.Aux[Repr, K0, V0]
44+
): HasIterableOps.Aux[Repr, (K0, V0)] = hasMapOps
6245

6346
}
Lines changed: 11 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
package strawman.collection
22
package decorators
33

4-
import scala.annotation.unchecked.uncheckedVariance
5-
64
/**
75
* Type class witnessing that a collection representation type `Repr`
8-
* has elements of type `A` and has a conversion to `MapOps[A, CC2, C]`
9-
* for some types `CC2[_, _]` and `C`.
6+
* has keys of type `K`, values of type `V` and has a conversion to `MapOps[K, V, _, _]`.
107
*
118
* This type enables simple enrichment of `Map`s with extension methods.
129
*
@@ -20,60 +17,33 @@ trait HasMapOps[Repr] extends HasIterableOps[Repr] {
2017
/** The type of values */
2118
type V
2219

23-
/** The type constructor returned by transformation operations that might change the types of key and value (e.g. `HashMap`) */
24-
type CC2[_, +_] <: IterableOps[_, AnyConstr, _]
25-
2620
type A = (K, V)
2721

28-
type CC[X] = Iterable[X]
29-
30-
/** A conversion from the representation type `Repr` to `MapOps[K, V, CC2, C]` */
31-
val conversion: Repr => MapOps[K, V, CC2, C]
22+
/** A conversion from the representation type `Repr` to `MapOps[K, V, _, _]` */
23+
val conversion: Repr => MapOps[K, V, ({ type l[X, +Y] = IterableOps[_, AnyConstr, _] })#l, _]
3224

3325
}
3426

3527
object HasMapOps extends LowPriorityHasMapOps {
3628

3729
// 1. Map collections
38-
implicit def mapHasMapOps[CC20[X, +Y] <: MapOps[X, Y, CC20, CC20[X, Y]], K0, V0]: HasMapOps.Aux[CC20[K0, V0], K0, V0, CC20, CC20[K0, V0]] =
39-
new HasMapOps[CC20[K0, V0]] {
40-
type K = K0
41-
type V = V0
42-
type CC2[X, +Y] = CC20[X, Y]
43-
type C = CC20[K, V]
44-
val conversion: CC20[K0, V0] => MapOps[K0, V0, CC20, CC20[K0, V0]] = c => c
45-
}
46-
47-
// 2. Sorted Map collections
48-
implicit def sortedMapHasMapOps[CC20[X, +Y] <: Map[X, Y] with SortedMapOps[X, Y, CC20, CC20[X, Y]], K0, V0]: HasMapOps.Aux[CC20[K0, V0], K0, V0, Map, CC20[K0, V0]] =
49-
new HasMapOps[CC20[K0, V0]] {
50-
type K = K0
51-
type V = V0
52-
type CC2[X, +Y] = Map[X, Y]
53-
type C = CC20[K, V]
54-
val conversion: CC20[K0, V0] => MapOps[K0, V0, Map, CC20[K0, V0]] = c => c
55-
}
56-
57-
// 3. MapView
58-
implicit def mapViewHasMapOps[CC20[X, +Y] <: MapView[X, Y], K0, V0]: HasMapOps.Aux[CC20[K0, V0], K0, V0, ({ type l[X, +Y] = View[(X, Y)] })#l, View[(K0, V0)]] =
59-
new HasMapOps[CC20[K0, V0]] {
30+
implicit def mapHasMapOps[CC[X, +Y] <: MapOps[X, Y, ({ type l[X, +Y] = IterableOps[_, AnyConstr, _] })#l, _], K0, V0]: HasMapOps.Aux[CC[K0, V0], K0, V0] =
31+
new HasMapOps[CC[K0, V0]] {
6032
type K = K0
6133
type V = V0
62-
type CC2[X, +Y] = View[(X, Y)]
63-
type C = View[(K0, V0)]
64-
val conversion: CC20[K0, V0] => MapOps[K0, V0, ({ type l[X, Y] = View[(X, Y)] })#l, View[(K0, V0)]] = c => c
34+
val conversion: CC[K0, V0] => MapOps[K0, V0, ({ type l[X, +Y] = IterableOps[_, AnyConstr, _] })#l, _] = c => c
6535
}
6636

6737
}
6838

6939
trait LowPriorityHasMapOps {
7040

71-
type Aux[Repr, K0, V0, CC20[_, +_] <: IterableOps[_, AnyConstr, _], C0] =
72-
HasMapOps[Repr] { type K = K0; type V = V0; type CC2[X, +Y] = CC20[X, Y]; type C = C0 }
41+
type Aux[Repr, K0, V0] =
42+
HasMapOps[Repr] { type K = K0; type V = V0 }
7343

7444
// Makes `HasImmutableMapOps` instances visible in `HasMapOps` companion
75-
implicit def hasImmutableMapOpsHasMapOps[Repr, K0, V0, CC20[X, +Y] <: immutable.MapOps[X, Y, CC20, _], C0 <: immutable.MapOps[K0, V0, CC20, C0]](implicit
76-
hasImmutableMapOps: HasImmutableMapOps.Aux[Repr, K0, V0, CC20, C0]
77-
): HasMapOps.Aux[Repr, K0, V0, CC20, C0] = hasImmutableMapOps
45+
implicit def hasImmutableMapOpsHasMapOps[Repr, K0, V0](implicit
46+
hasImmutableMapOps: HasImmutableMapOps.Aux[Repr, K0, V0]
47+
): HasMapOps.Aux[Repr, K0, V0] = hasImmutableMapOps
7848

7949
}

collections-contrib/src/main/scala/strawman/collection/decorators/HasSeqOps.scala

Lines changed: 19 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import scala.Predef.String
77
import strawman.collection.immutable.Range
88

99
/** Type class witnessing that a collection representation type `Repr` has
10-
* elements of type `A` and has a conversion to `SeqOps[A, CC, C]`.
10+
* elements of type `A` and has a conversion to `SeqOps[A, _, _]`.
1111
*
1212
* This type enables simple enrichment of `Seq`s with extension methods which
1313
* can make full use of the mechanics of the Scala collections framework in
@@ -16,68 +16,49 @@ import strawman.collection.immutable.Range
1616
* @see [[scala.collection.decorators.HasIterableOps]]
1717
*/
1818
trait HasSeqOps[Repr] extends HasIterableOps[Repr] {
19-
/** A conversion from the representation type `Repr` to `SeqOps[A, CC, C]`. */
20-
val conversion: Repr => SeqOps[A, CC, C]
19+
/** A conversion from the representation type `Repr` to `SeqOps[A, _, _]`. */
20+
val conversion: Repr => SeqOps[A, AnyConstr, _]
2121
}
2222

2323
object HasSeqOps {
2424

2525
/** A type alias for `HasSeqOps` that moves type members to type parameters */
26-
type Aux[Repr, A0, CC0[_], C0] = HasSeqOps[Repr] { type A = A0; type CC[X] = CC0[X]; type C = C0 }
26+
type Aux[Repr, A0] = HasSeqOps[Repr] { type A = A0 }
2727

2828
// we want to provide implicit instances that unify all possible types `X` with a `SeqOps[A, CC, C]`
2929
// 1. Seq collections
30-
implicit def seqHasSeqOps[CC0[X] <: SeqOps[X, CC0, CC0[X]], A0]: HasSeqOps.Aux[CC0[A0], A0, CC0, CC0[A0]] =
31-
new HasSeqOps[CC0[A0]] {
30+
implicit def seqHasSeqOps[CC[X] <: SeqOps[X, AnyConstr, _], A0]: HasSeqOps.Aux[CC[A0], A0] =
31+
new HasSeqOps[CC[A0]] {
3232
type A = A0
33-
type CC[X] = CC0[X]
34-
type C = CC0[A]
35-
val conversion: CC0[A0] => SeqOps[A0, CC0, CC0[A0]] = c => c
33+
val conversion: CC[A0] => SeqOps[A0, AnyConstr, _] = c => c
3634
}
3735

38-
// 2. Seq views
39-
implicit def viewHasSeqOps[CC0[X] <: SeqView[X], A0]: HasSeqOps.Aux[CC0[A0], A0, View, View[A0]] =
40-
new HasSeqOps[CC0[A0]] {
41-
type A = A0
42-
type CC[X] = View[X]
43-
type C = View[A0]
44-
val conversion: CC0[A0] => SeqOps[A0, View, View[A0]] = c => c
45-
}
46-
47-
// 3. String
48-
implicit def stringHasSeqOps: HasSeqOps.Aux[String, Char, immutable.IndexedSeq, String] =
36+
// 2. String
37+
implicit def stringHasSeqOps: HasSeqOps.Aux[String, Char] =
4938
new HasSeqOps[String] {
5039
type A = Char
51-
type CC[X] = immutable.IndexedSeq[X]
52-
type C = String
53-
val conversion: String => SeqOps[Char, immutable.IndexedSeq, String] = stringToStringOps
40+
val conversion: String => SeqOps[Char, AnyConstr, _] = stringToStringOps
5441
}
5542

56-
// 4. StringView
57-
implicit def stringViewHasSeqOps: HasSeqOps.Aux[StringView, Char, View, View[Char]] =
43+
// 3. StringView
44+
implicit def stringViewHasSeqOps: HasSeqOps.Aux[StringView, Char] =
5845
new HasSeqOps[StringView] {
5946
type A = Char
60-
type CC[X] = View[X]
61-
type C = View[Char]
62-
val conversion: StringView => SeqOps[Char, View, View[Char]] = v => v
47+
val conversion: StringView => SeqOps[Char, AnyConstr, _] = v => v
6348
}
6449

65-
// 5. Array
66-
implicit def arrayHasSeqOps[A0]: HasSeqOps.Aux[Array[A0], A0, immutable.IndexedSeq, Array[A0]] =
50+
// 4. Array
51+
implicit def arrayHasSeqOps[A0]: HasSeqOps.Aux[Array[A0], A0] =
6752
new HasSeqOps[Array[A0]] {
6853
type A = A0
69-
type CC[X] = immutable.IndexedSeq[X]
70-
type C = Array[A0]
71-
val conversion: Array[A0] => SeqOps[A0, immutable.IndexedSeq, Array[A0]] = arrayToArrayOps
54+
val conversion: Array[A0] => SeqOps[A0, AnyConstr, _] = arrayToArrayOps
7255
}
7356

74-
// 6. Range collections
75-
implicit def rangeHasSeqOps[Repr <: Range]: HasSeqOps.Aux[Repr, Int, immutable.IndexedSeq, immutable.IndexedSeq[Int]] =
57+
// 5. Range collections
58+
implicit def rangeHasSeqOps[Repr <: Range]: HasSeqOps.Aux[Repr, Int] =
7659
new HasSeqOps[Repr] {
7760
type A = Int
78-
type CC[X] = immutable.IndexedSeq[X]
79-
type C = immutable.IndexedSeq[Int]
80-
val conversion: Repr => SeqOps[Int, immutable.IndexedSeq, immutable.IndexedSeq[Int]] = r => r
61+
val conversion: Repr => SeqOps[Int, AnyConstr, _] = r => r
8162
}
8263

8364
}

0 commit comments

Comments
 (0)