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

Commit bcd4413

Browse files
committed
Remove the boilerplate associated with the new design (and more)
- The respective `CC` types are exposed (to `protected[this]`) through aliases `IterableCC`, `SortedIterableCC`, `MapCC` and `SortedMapCC` in the respective `Ops` traits, plus a `BitSetC` for the shared `BitSetOps` trait. - This allows defining `fromSpecificIterable`, `newSpecificBuilder` and `empty` (for all but `Iterable`) in the respective collection traits `Iterable`, `SortedSet`, `Map` and `SortedMap` (*not* in their `Ops` traits) where the `CC` type is visible and set to a concrete type but can still be refined in subtypes. This gives us a valid implementation until a concrete collection type with a refined `CC` gets defined. In this case the inherited implementations have the wrong type, so the user is forced to override them. - Implementations of `fromSpecificIterable`, `newSpecificBuilder` and `empty` can be removed from almost all collection implementations except the ones where they need to be refined even further than what a factory can provide (e.g. `IntMap`, `PriorityQueue`). - Factories are generally overridden in abstract collection types that refine a `CC` (e.g. `Iterable` -> `Seq` -> `immutable.Set` -> `immutable.IndexedSeq`) so that concrete implementations without further refinement do not need to override them. - DefaultMap is deprecated because there is no more boilerplate left that it could implement. - `sortedFromIterable`, `mapFromIterable` and `sortedMapFromIterable` are treated the same way as `fromIterable`. They are implemented as `inline final` calls to the respective factory method. Fixes #335
1 parent a42fc3d commit bcd4413

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+225
-408
lines changed

collections-contrib/src/main/scala/strawman/collection/MultiDict.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ trait MultiDict[K, V]
1111
with MultiDictOps[K, V, MultiDict, MultiDict[K, V]]
1212
with Equals {
1313

14+
def multiMapFactory: MapFactory[MultiDictCC] = MultiDict
15+
16+
override protected[this] def fromSpecificIterable(coll: Iterable[(K, V)]): MultiDictCC[K, V] = multiMapFactory.from(coll)
17+
override protected[this] def newSpecificBuilder(): mutable.Builder[(K, V), MultiDictCC[K, V]] = multiMapFactory.newBuilder[K, V]()
18+
1419
def canEqual(that: Any): Boolean = true
1520

1621
override def equals(o: Any): Boolean = o match {
@@ -35,7 +40,9 @@ trait MultiDict[K, V]
3540
trait MultiDictOps[K, V, +CC[X, Y] <: MultiDict[X, Y], +C <: MultiDict[K, V]]
3641
extends IterableOps[(K, V), Iterable, C] {
3742

38-
def multiMapFactory: MapFactory[CC]
43+
protected[this] type MultiDictCC[K, V] = CC[K, V]
44+
45+
def multiMapFactory: MapFactory[MultiDictCC]
3946

4047
protected[this] def multiMapFromIterable[L, W](it: Iterable[(L, W)]): CC[L, W] =
4148
multiMapFactory.from(it)

collections-contrib/src/main/scala/strawman/collection/SortedMultiDict.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@ trait SortedMultiDict[K, V]
1212

1313
def unsorted: MultiDict[K, V] = this
1414

15+
override protected[this] def fromSpecificIterable(coll: Iterable[(K, V)]): SortedMultiDictCC[K, V] = sortedMultiMapFactory.from(coll)
16+
override protected[this] def newSpecificBuilder(): mutable.Builder[(K, V), SortedMultiDictCC[K, V]] = sortedMultiMapFactory.newBuilder[K, V]()
1517
}
1618

1719
trait SortedMultiDictOps[K, V, +CC[X, Y] <: MultiDict[X, Y], +C <: MultiDict[K, V]]
1820
extends MultiDictOps[K, V, MultiDict, C]
1921
with SortedOps[K, C] {
2022

21-
def multiMapFactory: MapFactory[MultiDict] = MultiDict
22-
def sortedMultiMapFactory: SortedMapFactory[CC]
23+
protected[this] type SortedMultiDictCC[K, V] = CC[K, V]
24+
25+
def sortedMultiMapFactory: SortedMapFactory[SortedMultiDictCC]
2326

2427
protected[this] def sortedFromIterable[L : Ordering, W](it: Iterable[(L, W)]): CC[L, W]
2528
protected[this] def sortedFromSets[L : Ordering, W](it: Iterable[(L, Set[W])]): CC[L, W] =

collections-contrib/src/main/scala/strawman/collection/SortedMultiSet.scala

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,23 @@ trait SortedMultiSet[A]
1212

1313
def unsorted: MultiSet[A] = this
1414

15+
override protected[this] def fromSpecificIterable(coll: Iterable[A]): SortedIterableCC[A] = sortedIterableFactory.from(coll)
16+
override protected[this] def newSpecificBuilder(): mutable.Builder[A, SortedIterableCC[A]] = sortedIterableFactory.newBuilder[A]()
17+
18+
protected[this] def sortedFromIterable[B : Ordering](it: strawman.collection.Iterable[B]): SortedIterableCC[B] = sortedIterableFactory.from(it)
19+
20+
def sortedIterableFactory: SortedIterableFactory[SortedIterableCC] = SortedMultiSet
1521
}
1622

1723
trait SortedMultiSetOps[A, +CC[X] <: MultiSet[X], +C <: MultiSet[A]]
1824
extends MultiSetOps[A, MultiSet, C]
1925
with SortedOps[A, C] {
2026

21-
def sortedIterableFactory: SortedIterableFactory[CC]
27+
protected[this] type SortedIterableCC[X] = CC[X]
28+
29+
def sortedIterableFactory: SortedIterableFactory[SortedIterableCC]
2230

23-
protected[this] def sortedFromIterable[B : Ordering](it: Iterable[B]): CC[B]
31+
protected[this] def sortedFromIterable[B : Ordering](it: Iterable[B]): SortedIterableCC[B]
2432
protected[this] def sortedFromOccurrences[B : Ordering](it: Iterable[(B, Int)]): CC[B] =
2533
sortedFromIterable(it.view.flatMap { case (b, n) => View.Fill(n)(b) })
2634

collections-contrib/src/main/scala/strawman/collection/immutable/MultiDict.scala

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@ class MultiDict[K, V] private (elems: Map[K, Set[V]])
1818

1919
def sets: Map[K, Set[V]] = elems
2020

21-
def iterableFactory: IterableFactory[Iterable] = Iterable
22-
def multiMapFactory: MapFactory[MultiDict] = MultiDict
23-
24-
protected[this] def fromSpecificIterable(coll: collection.Iterable[(K, V)]): MultiDict[K, V] = multiMapFromIterable(coll)
25-
protected[this] def newSpecificBuilder(): Builder[(K, V), MultiDict[K, V]] = multiMapFactory.newBuilder[K, V]()
21+
override def multiMapFactory: MapFactory[MultiDict] = MultiDict
2622

2723
/**
2824
* @return a new multidict that contains all the entries of this multidict

collections-contrib/src/main/scala/strawman/collection/immutable/MultiSet.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ class MultiSet[A] private (elems: Map[A, Int])
1717

1818
def occurrences: Map[A, Int] = elems
1919

20-
def iterableFactory: IterableFactory[MultiSet] = MultiSet
21-
protected[this] def fromSpecificIterable(coll: collection.Iterable[A]): MultiSet[A] = fromIterable(coll)
22-
protected[this] def newSpecificBuilder(): Builder[A, MultiSet[A]] = iterableFactory.newBuilder()
20+
override def iterableFactory: IterableFactory[MultiSet] = MultiSet
2321

2422
/**
2523
* @return an immutable multiset containing all the elements of this multiset

collections-contrib/src/main/scala/strawman/collection/immutable/SortedMultiDict.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@ class SortedMultiDict[K, V] private (elems: SortedMap[K, Set[V]])(implicit val o
1717
with collection.IterableOps[(K, V), Iterable, SortedMultiDict[K, V]] {
1818

1919
def sortedMultiMapFactory: SortedMapFactory[SortedMultiDict] = SortedMultiDict
20-
def iterableFactory: IterableFactory[Iterable] = Iterable
2120

22-
protected[this] def fromSpecificIterable(coll: collection.Iterable[(K, V)]): SortedMultiDict[K, V] = sortedMultiMapFactory.from(coll)
2321
protected[this] def sortedFromIterable[L: Ordering, W](it: collection.Iterable[(L, W)]): SortedMultiDict[L, W] = sortedMultiMapFactory.from(it)
24-
protected[this] def newSpecificBuilder(): Builder[(K, V), SortedMultiDict[K, V]] = sortedMultiMapFactory.newBuilder()
2522

2623
def sets: SortedMap[K, Set[V]] = elems
2724

collections-contrib/src/main/scala/strawman/collection/immutable/SortedMultiSet.scala

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,8 @@ class SortedMultiSet[A] private (elems: SortedMap[A, Int])(implicit val ordering
1717

1818
def occurrences: SortedMap[A, Int] = elems
1919

20-
def iterableFactory: IterableFactory[MultiSet] = MultiSet
21-
def sortedIterableFactory: SortedIterableFactory[SortedMultiSet] = SortedMultiSet
22-
23-
protected[this] def fromSpecificIterable(coll: collection.Iterable[A]): SortedMultiSet[A] = sortedFromIterable(coll)
24-
protected[this] def sortedFromIterable[B : Ordering](it: collection.Iterable[B]): SortedMultiSet[B] = sortedIterableFactory.from(it)
25-
protected[this] def newSpecificBuilder(): Builder[A, SortedMultiSet[A]] = sortedIterableFactory.newBuilder()
20+
override def iterableFactory: IterableFactory[MultiSet] = MultiSet
21+
override def sortedIterableFactory: SortedIterableFactory[SortedMultiSet] = SortedMultiSet
2622

2723
def rangeImpl(from: Option[A], until: Option[A]): SortedMultiSet[A] =
2824
new SortedMultiSet(elems.rangeImpl(from, until))

collections-contrib/src/main/scala/strawman/collection/mutable/MultiDict.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ class MultiDict[K, V] private (elems: Map[K, Set[V]])
1515
with Growable[(K, V)]
1616
with Shrinkable[(K, V)] {
1717

18-
def iterableFactory: IterableFactory[collection.Iterable] = collection.Iterable
19-
def multiMapFactory: MapFactory[MultiDict] = MultiDict
20-
protected[this] def fromSpecificIterable(coll: collection.Iterable[(K, V)]): MultiDict[K, V] = multiMapFactory.from(coll)
21-
protected[this] def newSpecificBuilder(): Builder[(K, V), MultiDict[K, V]] = multiMapFactory.newBuilder()
18+
override def multiMapFactory: MapFactory[MultiDict] = MultiDict
2219

2320
def sets: collection.Map[K, collection.Set[V]] = elems
2421

collections-contrib/src/main/scala/strawman/collection/mutable/MultiSet.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ class MultiSet[A] private (val elems: Map[A, Int])
1313
with Growable[A]
1414
with Shrinkable [A] {
1515

16-
def iterableFactory: IterableFactory[MultiSet] = MultiSet
17-
protected[this] def fromSpecificIterable(coll: collection.Iterable[A]): MultiSet[A] = fromIterable(coll)
18-
protected[this] def newSpecificBuilder(): Builder[A, MultiSet[A]] = iterableFactory.newBuilder()
16+
override def iterableFactory: IterableFactory[MultiSet] = MultiSet
1917

2018
def occurrences: collection.Map[A, Int] = elems
2119

collections-contrib/src/main/scala/strawman/collection/mutable/SortedMultiDict.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,9 @@ class SortedMultiDict[K, V] private (elems: SortedMap[K, Set[V]])(implicit val o
1717

1818
def sets: collection.SortedMap[K, collection.Set[V]] = elems
1919

20-
def iterableFactory: IterableFactory[collection.Iterable] = collection.Iterable
2120
def sortedMultiMapFactory: SortedMapFactory[SortedMultiDict] = SortedMultiDict
2221

23-
protected[this] def fromSpecificIterable(coll: collection.Iterable[(K, V)]): SortedMultiDict[K, V] = sortedMultiMapFactory.from(coll)
2422
protected[this] def sortedFromIterable[L: Ordering, W](it: collection.Iterable[(L, W)]): SortedMultiDict[L, W] = sortedMultiMapFactory.from(it)
25-
protected[this] def newSpecificBuilder(): Builder[(K, V), SortedMultiDict[K, V]] = sortedMultiMapFactory.newBuilder()
2623

2724
def rangeImpl(from: Option[K], until: Option[K]): SortedMultiDict[K, V] =
2825
new SortedMultiDict(elems.rangeImpl(from, until))

collections-contrib/src/main/scala/strawman/collection/mutable/SortedMultiSet.scala

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@ class SortedMultiSet[A] private (elems: SortedMap[A, Int])(implicit val ordering
1717

1818
def occurrences: collection.SortedMap[A, Int] = elems
1919

20-
def iterableFactory: IterableFactory[MultiSet] = MultiSet
21-
def sortedIterableFactory: SortedIterableFactory[SortedMultiSet] = SortedMultiSet
22-
23-
protected[this] def fromSpecificIterable(coll: collection.Iterable[A]): SortedMultiSet[A] = sortedFromIterable(coll)
24-
protected[this] def sortedFromIterable[B: Ordering](it: collection.Iterable[B]): SortedMultiSet[B] = sortedIterableFactory.from(it)
25-
protected[this] def newSpecificBuilder(): Builder[A, SortedMultiSet[A]] = sortedIterableFactory.newBuilder()
20+
override def sortedIterableFactory: SortedIterableFactory[SortedMultiSet] = SortedMultiSet
2621

2722
def rangeImpl(from: Option[A], until: Option[A]): SortedMultiSet[A] =
2823
new SortedMultiSet(elems.rangeImpl(from, until))

collections/src/main/scala/strawman/collection/BitSet.scala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ import scala.Predef.{assert, intWrapper}
1818
* @define coll bitset
1919
* @define Coll `BitSet`
2020
*/
21-
trait BitSet extends SortedSet[Int] with BitSetOps[BitSet]
21+
trait BitSet extends SortedSet[Int] with BitSetOps[BitSet] {
22+
override protected[this] def fromSpecificIterable(coll: Iterable[Int]): BitSetC = bitSetFactory.fromSpecific(coll)
23+
override protected[this] def newSpecificBuilder(): Builder[Int, BitSetC] = bitSetFactory.newBuilder()
24+
override def empty: BitSetC = bitSetFactory.empty
25+
}
2226

2327
object BitSet extends SpecificIterableFactory[Int, BitSet] {
2428
def empty: BitSet = immutable.BitSet.empty
@@ -31,6 +35,10 @@ trait BitSetOps[+C <: BitSet with BitSetOps[C]]
3135
extends SortedSetOps[Int, SortedSet, C] { self =>
3236
import BitSetOps._
3337

38+
def bitSetFactory: SpecificIterableFactory[Int, BitSetC]
39+
40+
protected[this] type BitSetC = C
41+
3442
final def ordering: Ordering[Int] = Ordering.Int
3543

3644
/** The number of words (each with 64 bits) making up the set */

collections/src/main/scala/strawman/collection/DefaultMap.scala

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,12 @@
99
package strawman
1010
package collection
1111

12+
import scala.deprecated
13+
1214
/** A default map which builds a default `immutable.Map` implementation for all
1315
* transformations.
1416
*
15-
* Instances that inherit from `DefaultMap[K, V]` still have to define:
16-
* {{{
17-
* def get(key: K): Option[V]
18-
* def iterator(): Iterator[(K, V)]
19-
* }}}
20-
*
21-
* It might also be advisable to override `foreach` or `size` if efficient
22-
* implementations can be found.
23-
*
2417
* @since 2.8
2518
*/
26-
trait DefaultMap[K, +V] extends Map[K, V] { self =>
27-
28-
// Members declared in IterableOps
29-
def iterableFactory: IterableFactory[Iterable] = Iterable
30-
protected[this] def fromSpecificIterable(coll: Iterable[(K, V)]): Map[K,V] = mapFactory.from(coll)
31-
protected[this] def newSpecificBuilder(): mutable.Builder[(K, V), Map[K,V]] = mapFactory.newBuilder()
32-
33-
// Members declared in MapOps
34-
def mapFactory: MapFactory[Map] = Map
35-
def empty: Map[K,V] = mapFactory.empty
36-
}
19+
@deprecated("DefaultMap is no longer necessary; extend Map directly", "2.13.0")
20+
trait DefaultMap[K, +V] extends Map[K, V]

collections/src/main/scala/strawman/collection/Iterable.scala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ trait Iterable[+A] extends IterableOnce[A] with IterableOps[A, Iterable, Iterabl
2626
//TODO scalac generates an override for this in AbstractMap; Making it final leads to a VerifyError
2727
protected[this] def coll: this.type = this
2828

29+
protected[this] def fromSpecificIterable(coll: Iterable[A]): IterableCC[A] = iterableFactory.from(coll)
30+
protected[this] def newSpecificBuilder(): Builder[A, IterableCC[A]] = iterableFactory.newBuilder[A]()
31+
32+
def iterableFactory: IterableFactory[IterableCC] = Iterable
2933
}
3034

3135
/** Base trait for Iterable operations
@@ -64,6 +68,8 @@ trait Iterable[+A] extends IterableOnce[A] with IterableOps[A, Iterable, Iterabl
6468
*/
6569
trait IterableOps[+A, +CC[_], +C] extends Any with IterableOnce[A] {
6670

71+
protected[this] type IterableCC[X] = CC[X]
72+
6773
/**
6874
* @return This collection as an `Iterable[A]`. No new collection will be built if `this` is already an `Iterable[A]`.
6975
*/
@@ -91,7 +97,7 @@ trait IterableOps[+A, +CC[_], +C] extends Any with IterableOnce[A] {
9197
/**
9298
* @return The companion object of this ${coll}, providing various factory methods.
9399
*/
94-
def iterableFactory: IterableFactory[CC]
100+
def iterableFactory: IterableFactory[IterableCC]
95101

96102
/**
97103
* @return a strict builder for the same collection type.
@@ -1251,4 +1257,4 @@ object Iterable extends IterableFactory.Delegate[Iterable](immutable.Iterable) {
12511257
implicit def toLazyZipOps[A, CC[X] <: Iterable[X]](that: CC[A]): LazyZipOps[A, CC[A]] = new LazyZipOps(that)
12521258
}
12531259

1254-
abstract class AbstractIterable[+A] extends Iterable[A]
1260+
abstract class AbstractIterable[+A] extends Iterable[A]

collections/src/main/scala/strawman/collection/Map.scala

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ trait Map[K, +V]
1515
with MapOps[K, V, Map, Map[K, V]]
1616
with Equals {
1717

18+
override protected[this] def fromSpecificIterable(coll: Iterable[(K, V)]): MapCC[K, V] = mapFactory.from(coll)
19+
override protected[this] def newSpecificBuilder(): mutable.Builder[(K, V), MapCC[K, V]] = mapFactory.newBuilder[K, V]()
20+
21+
def mapFactory: strawman.collection.MapFactory[MapCC] = Map
22+
23+
def empty: MapCC[K, V] = mapFactory.empty
24+
1825
def canEqual(that: Any): Boolean = true
1926

2027
override def equals(o: Any): Boolean = o match {
@@ -52,7 +59,14 @@ trait MapOps[K, +V, +CC[X, Y] <: MapOps[X, Y, CC, _], +C]
5259
with PartialFunction[K, V]
5360
with Equals {
5461

55-
def mapFactory: MapFactory[CC]
62+
protected[this] type MapCC[K, V] = CC[K, V]
63+
64+
/** Similar to `fromIterable`, but returns a Map collection type.
65+
* Note that the return type is now `CC[K2, V2]` aka `MapCC[K2, V2]` rather than `IterableCC[(K2, V2)]`.
66+
*/
67+
@`inline` protected[this] final def mapFromIterable[K2, V2](it: Iterable[(K2, V2)]): CC[K2, V2] = mapFactory.from(it)
68+
69+
def mapFactory: MapFactory[MapCC]
5670

5771
/** Optionally returns the value associated with a key.
5872
*
@@ -104,11 +118,7 @@ trait MapOps[K, +V, +CC[X, Y] <: MapOps[X, Y, CC, _], +C]
104118
*/
105119
@SerialVersionUID(3L)
106120
protected class KeySet extends Set[K] with GenKeySet {
107-
def iterableFactory: IterableFactory[Set] = Set
108-
protected[this] def fromSpecificIterable(coll: Iterable[K]): Set[K] = fromIterable(coll)
109-
protected[this] def newSpecificBuilder(): Builder[K, Set[K]] = iterableFactory.newBuilder()
110121
def diff(that: Set[K]): Set[K] = fromSpecificIterable(view.filterNot(that))
111-
def empty: Set[K] = iterableFactory.empty
112122
}
113123

114124
/** A generic trait that is reused by keyset implementations */

collections/src/main/scala/strawman/collection/Seq.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ trait Seq[+A]
2020
with SeqOps[A, Seq, Seq[A]]
2121
with Equals {
2222

23-
def iterableFactory: SeqFactory[Seq]
23+
override def iterableFactory: SeqFactory[IterableCC] = Seq
2424

2525
/** Method called from equality methods, so that user-defined subclasses can
2626
* refuse to be equal to other collections of the same kind.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ trait Set[A]
2828

2929
override def hashCode(): Int = Set.setHash(toIterable)
3030

31+
def empty: IterableCC[A] = iterableFactory.empty
3132
}
3233

3334
/** Base trait for set operations

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

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,35 @@ import strawman.collection.immutable.TreeMap
55
import strawman.collection.mutable.Builder
66

77
import scala.annotation.unchecked.uncheckedVariance
8-
import scala.{Boolean, Int, Option, Ordering, PartialFunction, Serializable, SerialVersionUID, `inline`}
8+
import scala.{Boolean, Int, Option, Ordering, PartialFunction, Serializable, SerialVersionUID, `inline`, Any}
99

1010
/** Base type of sorted sets */
1111
trait SortedMap[K, +V]
1212
extends Map[K, V]
1313
with SortedMapOps[K, V, SortedMap, SortedMap[K, V]] {
14+
1415
def unsorted: Map[K, V] = this
16+
17+
override protected[this] def fromSpecificIterable(coll: Iterable[(K, V)]): SortedMapCC[K, V] = sortedMapFactory.from(coll)
18+
override protected[this] def newSpecificBuilder(): mutable.Builder[(K, V), SortedMapCC[K, V]] = sortedMapFactory.newBuilder[K, V]()
19+
20+
def sortedMapFactory: SortedMapFactory[SortedMapCC] = SortedMap
21+
22+
override def empty: SortedMapCC[K, V] = sortedMapFactory.empty
1523
}
1624

1725
trait SortedMapOps[K, +V, +CC[X, Y] <: Map[X, Y] with SortedMapOps[X, Y, CC, _], +C <: SortedMapOps[K, V, CC, C]]
1826
extends MapOps[K, V, Map, C]
1927
with SortedOps[K, C] {
2028

21-
def sortedMapFactory: SortedMapFactory[CC]
29+
protected[this] type SortedMapCC[K, V] = CC[K, V]
30+
31+
def sortedMapFactory: SortedMapFactory[SortedMapCC]
32+
33+
/** Similar to `mapFromIterable`, but returns a SortedMap collection type.
34+
* Note that the return type is now `CC[K2, V2]` aka `SortedMapCC[K2, V2]` rather than `MapCC[(K2, V2)]`.
35+
*/
36+
@`inline` protected[this] final def sortedMapFromIterable[K2, V2](it: Iterable[(K2, V2)])(implicit ordering: Ordering[K2]): CC[K2, V2] = sortedMapFactory.from(it)
2237

2338
def unsorted: Map[K, V]
2439

@@ -89,13 +104,7 @@ trait SortedMapOps[K, +V, +CC[X, Y] <: Map[X, Y] with SortedMapOps[X, Y, CC, _],
89104
/** The implementation class of the set returned by `keySet` */
90105
@SerialVersionUID(3L)
91106
protected class KeySortedSet extends SortedSet[K] with GenKeySet with GenKeySortedSet {
92-
def iterableFactory: IterableFactory[Set] = Set
93-
def sortedIterableFactory: SortedIterableFactory[SortedSet] = SortedSet
94-
protected[this] def fromSpecificIterable(coll: Iterable[K]): SortedSet[K] = sortedFromIterable(coll)
95-
protected[this] def newSpecificBuilder(): Builder[K, SortedSet[K]] = sortedIterableFactory.newBuilder()
96-
protected[this] def sortedFromIterable[B: Ordering](it: Iterable[B]): SortedSet[B] = sortedFromIterable(it)
97107
def diff(that: Set[K]): SortedSet[K] = fromSpecificIterable(view.filterNot(that))
98-
def empty: SortedSet[K] = sortedIterableFactory.empty
99108
def rangeImpl(from: Option[K], until: Option[K]): SortedSet[K] = {
100109
val map = SortedMapOps.this.rangeImpl(from, until)
101110
new map.KeySortedSet

0 commit comments

Comments
 (0)