diff options
Diffstat (limited to 'src')
80 files changed, 290 insertions, 167 deletions
diff --git a/src/compiler/scala/tools/nsc/doc/DefaultDocDriver.scala b/src/compiler/scala/tools/nsc/doc/DefaultDocDriver.scala index 5a8f67a095..8a1261a2f6 100644 --- a/src/compiler/scala/tools/nsc/doc/DefaultDocDriver.scala +++ b/src/compiler/scala/tools/nsc/doc/DefaultDocDriver.scala @@ -140,7 +140,7 @@ abstract class DefaultDocDriver extends DocDriver with ModelFrames with ModelToX if (idx == -1) str; else str.substring(idx + 1); }+ ")"); - else NodeSeq.Empty) ++ super.optional(cls))(NodeSeq.builderFactory) + else NodeSeq.Empty) ++ super.optional(cls))//(NodeSeq.builderFactory) } } diff --git a/src/library/scala/Array.scala b/src/library/scala/Array.scala index 249d80653c..30c1b99b83 100644 --- a/src/library/scala/Array.scala +++ b/src/library/scala/Array.scala @@ -27,12 +27,13 @@ class FallbackArrayBuilding { * Called instead of Array.newBuilder if the element type of an array * does not have a class manifest. Note that fallbackBuilder fcatory * needs an implicit parameter (otherwise it would not be dominated in implicit search - * by Array.builderFactory). We make sure that that implicit search is always + * by Array.canBuildFrom). We make sure that that implicit search is always * succesfull. */ - implicit def fallbackBuilderFactory[T](implicit m: DummyImplicit): BuilderFactory[T, GenericArray[T], Array[_]] = - new BuilderFactory[T, GenericArray[T], Array[_]] { + implicit def fallbackCanBuildFrom[T](implicit m: DummyImplicit): CanBuildFrom[Array[_], T, GenericArray[T]] = + new CanBuildFrom[Array[_], T, GenericArray[T]] { def apply(from: Array[_]) = GenericArray.newBuilder[T] + def apply() = GenericArray.newBuilder[T] } } @@ -46,8 +47,11 @@ object Array extends FallbackArrayBuilding { import runtime.BoxedArray; import scala.runtime.ScalaRunTime.boxArray; - implicit def builderFactory[T](implicit m: ClassManifest[T]): BuilderFactory[T, Array[T], Array[_]] = - new BuilderFactory[T, Array[T], Array[_]] { def apply(from: Array[_]) = ArrayBuilder.make[T]()(m) } + implicit def canBuildFrom[T](implicit m: ClassManifest[T]): CanBuildFrom[Array[_], T, Array[T]] = + new CanBuildFrom[Array[_], T, Array[T]] { + def apply(from: Array[_]) = ArrayBuilder.make[T]()(m) + def apply() = ArrayBuilder.make[T]()(m) + } def newBuilder[T](implicit m: ClassManifest[T]): ArrayBuilder[T] = ArrayBuilder.make[T]()(m) diff --git a/src/library/scala/Enumeration.scala b/src/library/scala/Enumeration.scala index f319afdf2e..7fa9180a36 100644 --- a/src/library/scala/Enumeration.scala +++ b/src/library/scala/Enumeration.scala @@ -14,7 +14,7 @@ package scala import scala.collection.SetLike import scala.collection.mutable.{Builder, AddingBuilder, Map, HashMap} import scala.collection.immutable.{Set, BitSet} -import scala.collection.generic.BuilderFactory +import scala.collection.generic.CanBuildFrom /** <p> * Defines a finite set of values specific to the enumeration. Typically @@ -233,7 +233,11 @@ abstract class Enumeration(initial: Int, names: String*) { /** A builder object for value sets */ def newBuilder: Builder[Value, ValueSet] = new AddingBuilder(empty) /** The implicit builder for value sets */ - implicit def builderFactory: BuilderFactory[Value, ValueSet, ValueSet] = new BuilderFactory[Value, ValueSet, ValueSet] { def apply(from: ValueSet) = newBuilder } + implicit def canBuildFrom: CanBuildFrom[ValueSet, Value, ValueSet] = + new CanBuildFrom[ValueSet, Value, ValueSet] { + def apply(from: ValueSet) = newBuilder + def apply() = newBuilder + } } /** The name of this enumeration. */ diff --git a/src/library/scala/LowPriorityImplicits.scala b/src/library/scala/LowPriorityImplicits.scala index d52101736c..376823e619 100644 --- a/src/library/scala/LowPriorityImplicits.scala +++ b/src/library/scala/LowPriorityImplicits.scala @@ -13,7 +13,7 @@ package scala import collection.mutable._ import collection.immutable.{WrappedString, Vector} -import collection.generic.BuilderFactory +import collection.generic.CanBuildFrom /** The `LowPriorityImplicits` class provides implicit values that * are valid in all Scala compilation units without explicit qualification, @@ -42,9 +42,10 @@ class LowPriorityImplicits { implicit def wrapString(s: String): WrappedString = new WrappedString(s) implicit def unwrapString(ws: WrappedString): String = ws.self - implicit def fallbackStringBuilderFactory[T]: BuilderFactory[T, collection.immutable.Vector[T], String] = - new BuilderFactory[T, collection.immutable.Vector[T], String] { + implicit def fallbackStringCanBuildFrom[T]: CanBuildFrom[String, T, collection.immutable.Vector[T]] = + new CanBuildFrom[String, T, collection.immutable.Vector[T]] { def apply(from: String) = scala.collection.immutable.Vector.newBuilder[T] + def apply() = scala.collection.immutable.Vector.newBuilder[T] } /** Can go away after next newstarr */ diff --git a/src/library/scala/Predef.scala b/src/library/scala/Predef.scala index 71fdd64832..708fe6db61 100644 --- a/src/library/scala/Predef.scala +++ b/src/library/scala/Predef.scala @@ -13,7 +13,7 @@ package scala import collection.immutable.StringOps import collection.mutable.ArrayOps -import collection.generic.BuilderFactory +import collection.generic.CanBuildFrom /** The <code>Predef</code> object provides definitions that are * accessible in all Scala compilation units without explicit @@ -215,8 +215,11 @@ object Predef extends LowPriorityImplicits { implicit def augmentString(x: String): StringOps = new StringOps(x) implicit def unaugmentString(x: StringOps): String = x.repr - implicit def stringBuilderFactory: BuilderFactory[Char, String, String] = - new BuilderFactory[Char, String, String] { def apply(from: String) = new scala.collection.mutable.StringBuilder } + implicit def stringCanBuildFrom: CanBuildFrom[String, Char, String] = + new CanBuildFrom[String, Char, String] { + def apply(from: String) = new scala.collection.mutable.StringBuilder + def apply() = new scala.collection.mutable.StringBuilder + } implicit def any2stringadd(x: Any) = new runtime.StringAdd(x) @@ -309,14 +312,14 @@ object Predef extends LowPriorityImplicits { implicit def conforms[A]: A <:< A = new (A <:< A) {def convert(x: A) = x} /** A type for which there is aways an implicit value. - * @see fallbackBuilderFactory in Array.scala + * @see fallbackCanBuildFrom in Array.scala */ class DummyImplicit object DummyImplicit { /** An implicit value yielding a DummyImplicit. - * @see fallbackBuilderFactory in Array.scala + * @see fallbackCanBuildFrom in Array.scala */ implicit def dummyImplicit: DummyImplicit = new DummyImplicit } diff --git a/src/library/scala/collection/Iterable.scala b/src/library/scala/collection/Iterable.scala index 6fbf980c19..7ebfdd09e7 100644 --- a/src/library/scala/collection/Iterable.scala +++ b/src/library/scala/collection/Iterable.scala @@ -66,7 +66,10 @@ trait Iterable[+A] extends Traversable[A] */ object Iterable extends TraversableFactory[Iterable] { - implicit def builderFactory[A]: BuilderFactory[A, Iterable[A], Coll] = new VirtualBuilderFactory[A] + implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, Iterable[A]] = + new GenericCanBuildFrom[A] { + def apply() = newBuilder[A] + } def newBuilder[A]: Builder[A, Iterable[A]] = immutable.Iterable.newBuilder[A] /** The minimum element of a non-empty sequence of ordered elements */ diff --git a/src/library/scala/collection/IterableLike.scala b/src/library/scala/collection/IterableLike.scala index 1a6b9d7aaf..bd72b16953 100644 --- a/src/library/scala/collection/IterableLike.scala +++ b/src/library/scala/collection/IterableLike.scala @@ -259,7 +259,7 @@ self => * If one of the two iterables is longer than the other, its remaining elements are ignored. * @param that The iterable providing the second half of each result pair */ - def zip[A1 >: A, B, That](that: Iterable[B])(implicit bf: BuilderFactory[(A1, B), That, Repr]): That = { + def zip[A1 >: A, B, That](that: Iterable[B])(implicit bf: CanBuildFrom[Repr, (A1, B), That]): That = { val b = bf(repr) val these = this.iterator val those = that.iterator @@ -288,7 +288,7 @@ self => * invoked where <code>m > n</code>. * */ - def zipAll[B, A1 >: A, That](that: Iterable[B], thisElem: A1, thatElem: B)(implicit bf: BuilderFactory[(A1, B), That, Repr]): That = { + def zipAll[B, A1 >: A, That](that: Iterable[B], thisElem: A1, thatElem: B)(implicit bf: CanBuildFrom[Repr, (A1, B), That]): That = { val b = bf(repr) val these = this.iterator val those = that.iterator @@ -303,7 +303,7 @@ self => /** Zips this iterable with its indices (startiong from 0). */ - def zipWithIndex[A1 >: A, That](implicit bf: BuilderFactory[(A1, Int), That, Repr]): That = { + def zipWithIndex[A1 >: A, That](implicit bf: CanBuildFrom[Repr, (A1, Int), That]): That = { val b = bf(repr) var i = 0 for (x <- this) { diff --git a/src/library/scala/collection/IterableProxyLike.scala b/src/library/scala/collection/IterableProxyLike.scala index e19c168eb5..6c4a9cddcb 100644 --- a/src/library/scala/collection/IterableProxyLike.scala +++ b/src/library/scala/collection/IterableProxyLike.scala @@ -34,9 +34,9 @@ trait IterableProxyLike[+A, +This <: IterableLike[A, This] with Iterable[A]] override def foldRight[B](z: B)(op: (A, B) => B): B = self.foldRight(z)(op) override def reduceRight[B >: A](op: (A, B) => B): B = self.reduceRight(op) override def toIterable: Iterable[A] = self.toIterable - override def zip[A1 >: A, B, That](that: Iterable[B])(implicit bf: BuilderFactory[(A1, B), That, This]): That = self.zip[A1, B, That](that)(bf) - override def zipAll[B, A1 >: A, That](that: Iterable[B], thisElem: A1, thatElem: B)(implicit bf: BuilderFactory[(A1, B), That, This]): That = self.zipAll(that, thisElem, thatElem)(bf) - override def zipWithIndex[A1 >: A, That](implicit bf: BuilderFactory[(A1, Int), That, This]): That = self.zipWithIndex(bf) + override def zip[A1 >: A, B, That](that: Iterable[B])(implicit bf: CanBuildFrom[This, (A1, B), That]): That = self.zip[A1, B, That](that)(bf) + override def zipAll[B, A1 >: A, That](that: Iterable[B], thisElem: A1, thatElem: B)(implicit bf: CanBuildFrom[This, (A1, B), That]): That = self.zipAll(that, thisElem, thatElem)(bf) + override def zipWithIndex[A1 >: A, That](implicit bf: CanBuildFrom[This, (A1, Int), That]): That = self.zipWithIndex(bf) override def head: A = self.head override def takeRight(n: Int): This = self.takeRight(n) override def dropRight(n: Int): This = self.dropRight(n) diff --git a/src/library/scala/collection/IterableView.scala b/src/library/scala/collection/IterableView.scala index b9c208fde3..0f6cf880aa 100644 --- a/src/library/scala/collection/IterableView.scala +++ b/src/library/scala/collection/IterableView.scala @@ -24,5 +24,9 @@ trait IterableView[+A, +Coll] extends IterableViewLike[A, Coll, IterableView[A, object IterableView { type Coll = TraversableView[_, C] forSome {type C <: Traversable[_]} - implicit def builderFactory[A]: BuilderFactory[A, IterableView[A, Iterable[_]], Coll] = new BuilderFactory[A, IterableView[A, Iterable[_]], Coll] { def apply(from: Coll) = new NoBuilder } + implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, IterableView[A, Iterable[_]]] = + new CanBuildFrom[Coll, A, IterableView[A, Iterable[_]]] { + def apply(from: Coll) = new NoBuilder + def apply() = new NoBuilder + } } diff --git a/src/library/scala/collection/IterableViewLike.scala b/src/library/scala/collection/IterableViewLike.scala index 5a2db7e02f..a531eef2f5 100644 --- a/src/library/scala/collection/IterableViewLike.scala +++ b/src/library/scala/collection/IterableViewLike.scala @@ -70,17 +70,17 @@ extends Iterable[A] with IterableLike[A, This] with TraversableView[A, Coll] wit self.iterator.zipAll(other.iterator, thisElem, thatElem) } - override def zip[A1 >: A, B, That](that: Iterable[B])(implicit bf: BuilderFactory[(A1, B), That, This]): That = { + override def zip[A1 >: A, B, That](that: Iterable[B])(implicit bf: CanBuildFrom[This, (A1, B), That]): That = { newZipped(that).asInstanceOf[That] // was: val b = bf(repr) // if (b.isInstanceOf[NoBuilder[_]]) newZipped(that).asInstanceOf[That] // else super.zip[A1, B, That](that)(bf) } - override def zipWithIndex[A1 >: A, That](implicit bf: BuilderFactory[(A1, Int), That, This]): That = + override def zipWithIndex[A1 >: A, That](implicit bf: CanBuildFrom[This, (A1, Int), That]): That = zip[A1, Int, That](Stream from 0)(bf) - override def zipAll[B, A1 >: A, That](that: Iterable[B], thisElem: A1, thatElem: B)(implicit bf: BuilderFactory[(A1, B), That, This]): That = + override def zipAll[B, A1 >: A, That](that: Iterable[B], thisElem: A1, thatElem: B)(implicit bf: CanBuildFrom[This, (A1, B), That]): That = newZippedAll(that, thisElem, thatElem).asInstanceOf[That] protected def newZipped[B](that: Iterable[B]): Transformed[(A, B)] = new Zipped[B] { diff --git a/src/library/scala/collection/LinearSeq.scala b/src/library/scala/collection/LinearSeq.scala index 4793d36aba..3de68a1c2c 100644 --- a/src/library/scala/collection/LinearSeq.scala +++ b/src/library/scala/collection/LinearSeq.scala @@ -38,6 +38,9 @@ trait LinearSeq[+A] extends Seq[A] * @since 2.8 */ object LinearSeq extends SeqFactory[LinearSeq] { - implicit def builderFactory[A]: BuilderFactory[A, LinearSeq[A], Coll] = new VirtualBuilderFactory[A] + implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, LinearSeq[A]] = + new GenericCanBuildFrom[A] { + def apply() = newBuilder[A] + } def newBuilder[A]: Builder[A, LinearSeq[A]] = immutable.LinearSeq.newBuilder[A] } diff --git a/src/library/scala/collection/Map.scala b/src/library/scala/collection/Map.scala index 3da7a3fcac..b53786308b 100644 --- a/src/library/scala/collection/Map.scala +++ b/src/library/scala/collection/Map.scala @@ -50,5 +50,5 @@ trait Map[A, +B] extends Iterable[(A, B)] with MapLike[A, B, Map[A, B]] { */ object Map extends ImmutableMapFactory[immutable.Map] { def empty[A, B]: immutable.Map[A, B] = immutable.Map.empty - implicit def builderFactory[A, B]: BuilderFactory[(A, B), Map[A, B], Coll] = new MapBuilderFactory[A, B] + implicit def canBuildFrom[A, B]: CanBuildFrom[Coll, (A, B), Map[A, B]] = new MapCanBuildFrom[A, B] } diff --git a/src/library/scala/collection/Seq.scala b/src/library/scala/collection/Seq.scala index 6e5f084a06..dd939b408f 100644 --- a/src/library/scala/collection/Seq.scala +++ b/src/library/scala/collection/Seq.scala @@ -46,7 +46,10 @@ object Seq extends SeqFactory[Seq] { private[collection] val hashSeed = "Seq".hashCode - implicit def builderFactory[A]: BuilderFactory[A, Seq[A], Coll] = new VirtualBuilderFactory[A] + implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, Seq[A]] = + new GenericCanBuildFrom[A] { + def apply() = newBuilder[A] + } def newBuilder[A]: Builder[A, Seq[A]] = immutable.Seq.newBuilder[A] @deprecated("use View instead") diff --git a/src/library/scala/collection/SeqLike.scala b/src/library/scala/collection/SeqLike.scala index 25be79b0d5..41cd6df77d 100644 --- a/src/library/scala/collection/SeqLike.scala +++ b/src/library/scala/collection/SeqLike.scala @@ -390,7 +390,7 @@ trait SeqLike[+A, +Repr] extends IterableLike[A, Repr] { self => * @return a sequence containing the elements of this * sequence and those of the given sequence <code>that</code>. */ - def union[B >: A, That](that: Seq[B])(implicit bf: BuilderFactory[B, That, Repr]): That = + def union[B >: A, That](that: Seq[B])(implicit bf: CanBuildFrom[Repr, B, That]): That = this ++ that /** <p> @@ -474,7 +474,7 @@ trait SeqLike[+A, +Repr] extends IterableLike[A, Repr] { self => * except that `replaced` elements starting from `from` are replaced * by `patch`. */ - def patch[B >: A, That](from: Int, patch: Seq[B], replaced: Int)(implicit bf: BuilderFactory[B, That, Repr]): That = { + def patch[B >: A, That](from: Int, patch: Seq[B], replaced: Int)(implicit bf: CanBuildFrom[Repr, B, That]): That = { val b = bf(repr) val (prefix, rest) = this.splitAt(from) b ++= toCollection(prefix) @@ -485,7 +485,7 @@ trait SeqLike[+A, +Repr] extends IterableLike[A, Repr] { self => /** Returns a copy of this sequence with the element at position `index` replaced by `elem`. */ - def updated[B >: A, That](index: Int, elem: B)(implicit bf: BuilderFactory[B, That, Repr]): That = { + def updated[B >: A, That](index: Int, elem: B)(implicit bf: CanBuildFrom[Repr, B, That]): That = { val b = bf(repr) val (prefix, rest) = this.splitAt(index) b ++= toCollection(prefix) @@ -496,7 +496,7 @@ trait SeqLike[+A, +Repr] extends IterableLike[A, Repr] { self => /** Returns a new sequence consisting of `elem` followed by the elements of this sequence. */ - def +:[B >: A, That](elem: B)(implicit bf: BuilderFactory[B, That, Repr]): That = { + def +:[B >: A, That](elem: B)(implicit bf: CanBuildFrom[Repr, B, That]): That = { val b = bf(repr) b += elem b ++= thisCollection @@ -505,7 +505,7 @@ trait SeqLike[+A, +Repr] extends IterableLike[A, Repr] { self => /** Returns a new sequence consisting of the elements of this sequence followed by `elem`. */ - def :+[B >: A, That](elem: B)(implicit bf: BuilderFactory[B, That, Repr]): That = { + def :+[B >: A, That](elem: B)(implicit bf: CanBuildFrom[Repr, B, That]): That = { val b = bf(repr) b ++= thisCollection b += elem @@ -518,7 +518,7 @@ trait SeqLike[+A, +Repr] extends IterableLike[A, Repr] { self => /** Returns a new sequence of given length containing the elements of this sequence followed by zero * or more occurrences of given elements. */ - def padTo[B >: A, That](len: Int, elem: B)(implicit bf: BuilderFactory[B, That, Repr]): That = { + def padTo[B >: A, That](len: Int, elem: B)(implicit bf: CanBuildFrom[Repr, B, That]): That = { val b = bf(repr) b.sizeHint(length max len) var diff = len - length diff --git a/src/library/scala/collection/SeqProxyLike.scala b/src/library/scala/collection/SeqProxyLike.scala index 4ea57a2e99..df4ea77f56 100644 --- a/src/library/scala/collection/SeqProxyLike.scala +++ b/src/library/scala/collection/SeqProxyLike.scala @@ -47,12 +47,12 @@ trait SeqProxyLike[+A, +This <: SeqLike[A, This] with Seq[A]] extends SeqLike[A, override def endsWith[B](that: Seq[B]): Boolean = self.endsWith(that) override def indexOfSeq[B >: A](that: Seq[B]): Int = self.indexOfSeq(that) override def contains(elem: Any): Boolean = self.contains(elem) - override def union[B >: A, That](that: Seq[B])(implicit bf: BuilderFactory[B, That, This]): That = self.union(that)(bf) + override def union[B >: A, That](that: Seq[B])(implicit bf: CanBuildFrom[This, B, That]): That = self.union(that)(bf) override def diff[B >: A, That](that: Seq[B]): This = self.diff(that) override def intersect[B >: A, That](that: Seq[B]): This = self.intersect(that) override def removeDuplicates: This = self.removeDuplicates - override def patch[B >: A, That](from: Int, patch: Seq[B], replaced: Int)(implicit bf: BuilderFactory[B, That, This]): That = self.patch(from, patch, replaced)(bf) - override def padTo[B >: A, That](len: Int, elem: B)(implicit bf: BuilderFactory[B, That, This]): That = self.padTo(len, elem)(bf) + override def patch[B >: A, That](from: Int, patch: Seq[B], replaced: Int)(implicit bf: CanBuildFrom[This, B, That]): That = self.patch(from, patch, replaced)(bf) + override def padTo[B >: A, That](len: Int, elem: B)(implicit bf: CanBuildFrom[This, B, That]): That = self.padTo(len, elem)(bf) override def indices: Range = self.indices override def view = self.view override def view(from: Int, until: Int) = self.view(from, until) diff --git a/src/library/scala/collection/SeqView.scala b/src/library/scala/collection/SeqView.scala index 40e1022754..89a96d6a2b 100644 --- a/src/library/scala/collection/SeqView.scala +++ b/src/library/scala/collection/SeqView.scala @@ -23,6 +23,10 @@ trait SeqView[+A, +Coll] extends SeqViewLike[A, Coll, SeqView[A, Coll]] object SeqView { type Coll = TraversableView[_, C] forSome {type C <: Traversable[_]} - implicit def builderFactory[A]: BuilderFactory[A, SeqView[A, Seq[_]], Coll] = new BuilderFactory[A, SeqView[A, Seq[_]], Coll] { def apply(from: Coll) = new NoBuilder } + implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, SeqView[A, Seq[_]]] = + new CanBuildFrom[Coll, A, SeqView[A, Seq[_]]] { + def apply(from: Coll) = new NoBuilder + def apply() = new NoBuilder + } } diff --git a/src/library/scala/collection/SeqViewLike.scala b/src/library/scala/collection/SeqViewLike.scala index 27389c8a5c..189e93406e 100644 --- a/src/library/scala/collection/SeqViewLike.scala +++ b/src/library/scala/collection/SeqViewLike.scala @@ -154,7 +154,7 @@ trait SeqViewLike[+A, override def reverse: This = newReversed.asInstanceOf[This] - override def patch[B >: A, That](from: Int, patch: Seq[B], replaced: Int)(implicit bf: BuilderFactory[B, That, This]): That = { + override def patch[B >: A, That](from: Int, patch: Seq[B], replaced: Int)(implicit bf: CanBuildFrom[This, B, That]): That = { newPatched(from, patch, replaced).asInstanceOf[That] // was: val b = bf(repr) // if (b.isInstanceOf[NoBuilder[_]]) newPatched(from, patch, replaced).asInstanceOf[That] @@ -163,7 +163,7 @@ trait SeqViewLike[+A, //TR TODO: updated, +: ed :+ ed - override def padTo[B >: A, That](len: Int, elem: B)(implicit bf: BuilderFactory[B, That, This]): That = + override def padTo[B >: A, That](len: Int, elem: B)(implicit bf: CanBuildFrom[This, B, That]): That = patch(length, fill(len - length)(elem), 0) override def stringPrefix = "SeqView" diff --git a/src/library/scala/collection/Set.scala b/src/library/scala/collection/Set.scala index f03f88261a..f58aff5356 100644 --- a/src/library/scala/collection/Set.scala +++ b/src/library/scala/collection/Set.scala @@ -36,5 +36,5 @@ trait Set[A] extends (A => Boolean) */ object Set extends SetFactory[Set] { override def empty[A]: Set[A] = immutable.Set.empty[A] - implicit def builderFactory[A]: BuilderFactory[A, Set[A], Coll] = setBuilderFactory[A] + implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, Set[A]] = setCanBuildFrom[A] } diff --git a/src/library/scala/collection/SortedMap.scala b/src/library/scala/collection/SortedMap.scala index a5a0ff1b45..8846e47bc3 100644 --- a/src/library/scala/collection/SortedMap.scala +++ b/src/library/scala/collection/SortedMap.scala @@ -31,7 +31,7 @@ trait SortedMap[A, +B] extends Map[A, B] with SortedMapLike[A, B, SortedMap[A, B * @since 2.8 */ object SortedMap extends ImmutableSortedMapFactory[immutable.SortedMap] { - implicit def builderFactory[A, B](implicit ord: Ordering[A]): BuilderFactory[(A, B), SortedMap[A, B], Coll] = new SortedMapBuilderFactory[A, B] + implicit def canBuildFrom[A, B](implicit ord: Ordering[A]): CanBuildFrom[Coll, (A, B), SortedMap[A, B]] = new SortedMapCanBuildFrom[A, B] def empty[A, B](implicit ord: Ordering[A]): immutable.SortedMap[A, B] = immutable.SortedMap.empty[A, B](ord) } diff --git a/src/library/scala/collection/SortedSet.scala b/src/library/scala/collection/SortedSet.scala index 33e5551824..eebfd44e44 100644 --- a/src/library/scala/collection/SortedSet.scala +++ b/src/library/scala/collection/SortedSet.scala @@ -27,7 +27,7 @@ trait SortedSet[A] extends Set[A] with SortedSetLike[A, SortedSet[A]] { * @since 2.8 */ object SortedSet extends ImmutableSortedSetFactory[immutable.SortedSet] { - implicit def builderFactory[A](implicit ord: Ordering[A]): BuilderFactory[A, SortedSet[A], Coll] = new SortedSetBuilderFactory[A] + implicit def canBuildFrom[A](implicit ord: Ordering[A]): CanBuildFrom[Coll, A, SortedSet[A]] = new SortedSetCanBuildFrom[A] def empty[A](implicit ord: Ordering[A]): immutable.SortedSet[A] = immutable.SortedSet.empty[A](ord) } diff --git a/src/library/scala/collection/Traversable.scala b/src/library/scala/collection/Traversable.scala index a5d4c6b18a..6abdc67a70 100644 --- a/src/library/scala/collection/Traversable.scala +++ b/src/library/scala/collection/Traversable.scala @@ -39,10 +39,10 @@ trait Traversable[+A] extends TraversableLike[A, Traversable[A]] override def isEmpty: Boolean override def size: Int override def hasDefiniteSize - override def ++[B >: A, That](that: Traversable[B])(implicit bf: BuilderFactory[B, That, Traversable[A]]): That - override def ++[B >: A, That](that: Iterator[B])(implicit bf: BuilderFactory[B, That, Traversable[A]]): That - override def map[B, That](f: A => B)(implicit bf: BuilderFactory[B, That, Traversable[A]]): That - override def flatMap[B, That](f: A => Traversable[B])(implicit bf: BuilderFactory[B, That, Traversable[A]]): That + override def ++[B >: A, That](that: Traversable[B])(implicit bf: CanBuildFrom[Traversable[A], B, That]): That + override def ++[B >: A, That](that: Iterator[B])(implicit bf: CanBuildFrom[Traversable[A], B, That]): That + override def map[B, That](f: A => B)(implicit bf: CanBuildFrom[Traversable[A], B, That]): That + override def flatMap[B, That](f: A => Traversable[B])(implicit bf: CanBuildFrom[Traversable[A], B, That]): That override def filter(p: A => Boolean): Traversable[A] override def remove(p: A => Boolean): Traversable[A] override def partition(p: A => Boolean): (Traversable[A], Traversable[A]) @@ -105,9 +105,10 @@ object Traversable extends TraversableFactory[Traversable] { self => /** provide break functionality separate from client code */ private[collection] val breaks: Breaks = new Breaks - implicit def builderFactory[A]: BuilderFactory[A, Traversable[A], Coll] = - new VirtualBuilderFactory[A] - + implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, Traversable[A]] = + new GenericCanBuildFrom[A] { + def apply() = newBuilder[A] + } def newBuilder[A]: Builder[A, Traversable[A]] = immutable.Traversable.newBuilder[A] } diff --git a/src/library/scala/collection/TraversableLike.scala b/src/library/scala/collection/TraversableLike.scala index 2716956cb9..9c066ab10e 100644 --- a/src/library/scala/collection/TraversableLike.scala +++ b/src/library/scala/collection/TraversableLike.scala @@ -126,7 +126,7 @@ self => * * @param that The traversable to append */ - def ++[B >: A, That](that: Traversable[B])(implicit bf: BuilderFactory[B, That, Repr]): That = { + def ++[B >: A, That](that: Traversable[B])(implicit bf: CanBuildFrom[Repr, B, That]): That = { val b = bf(repr) b ++= thisCollection b ++= that @@ -138,7 +138,7 @@ self => * * @param that The iterator to append */ - def ++[B >: A, That](that: Iterator[B])(implicit bf: BuilderFactory[B, That, Repr]): That = { + def ++[B >: A, That](that: Iterator[B])(implicit bf: CanBuildFrom[Repr, B, That]): That = { val b = bf(repr) b ++= thisCollection b ++= that @@ -151,7 +151,7 @@ self => * * @param f function to apply to each element. */ - def map[B, That](f: A => B)(implicit bf: BuilderFactory[B, That, Repr]): That = { + def map[B, That](f: A => B)(implicit bf: CanBuildFrom[Repr, B, That]): That = { val b = bf(repr) for (x <- this) b += f(x) b.result @@ -162,7 +162,7 @@ self => * * @param f the function to apply on each element. */ - def flatMap[B, That](f: A => Traversable[B])(implicit bf: BuilderFactory[B, That, Repr]): That = { + def flatMap[B, That](f: A => Traversable[B])(implicit bf: CanBuildFrom[Repr, B, That]): That = { val b = bf(repr) for (x <- this) b ++= f(x) b.result @@ -195,7 +195,7 @@ self => * @return the new traversable. */ @experimental - def filterMap[B, That](pf: PartialFunction[Any, B])(implicit bf: BuilderFactory[B, That, Repr]): That = { + def filterMap[B, That](pf: PartialFunction[Any, B])(implicit bf: CanBuildFrom[Repr, B, That]): That = { val b = bf(repr) for (x <- this) if (pf.isDefinedAt(x)) b += pf(x) b.result @@ -829,14 +829,14 @@ self => class WithFilter(p: A => Boolean) { - def map[B, That](f: A => B)(implicit bf: BuilderFactory[B, That, Repr]): That = { + def map[B, That](f: A => B)(implicit bf: CanBuildFrom[Repr, B, That]): That = { val b = bf(repr) for (x <- self) if (p(x)) b += f(x) b.result } - def flatMap[B, That](f: A => Traversable[B])(implicit bf: BuilderFactory[B, That, Repr]): That = { + def flatMap[B, That](f: A => Traversable[B])(implicit bf: CanBuildFrom[Repr, B, That]): That = { val b = bf(repr) for (x <- self) if (p(x)) b ++= f(x) diff --git a/src/library/scala/collection/TraversableProxyLike.scala b/src/library/scala/collection/TraversableProxyLike.scala index 34ebc667c6..2f2de590af 100644 --- a/src/library/scala/collection/TraversableProxyLike.scala +++ b/src/library/scala/collection/TraversableProxyLike.scala @@ -32,10 +32,10 @@ trait TraversableProxyLike[+A, +This <: TraversableLike[A, This] with Traversabl override def nonEmpty: Boolean = self.nonEmpty override def size: Int = self.size override def hasDefiniteSize = self.hasDefiniteSize - override def ++[B >: A, That](that: Traversable[B])(implicit bf: BuilderFactory[B, That, This]): That = self.++(that)(bf) - override def ++[B >: A, That](that: Iterator[B])(implicit bf: BuilderFactory[B, That, This]): That = self.++(that)(bf) - override def map[B, That](f: A => B)(implicit bf: BuilderFactory[B, That, This]): That = self.map(f)(bf) - override def flatMap[B, That](f: A => Traversable[B])(implicit bf: BuilderFactory[B, That, This]): That = self.flatMap(f)(bf) + override def ++[B >: A, That](that: Traversable[B])(implicit bf: CanBuildFrom[This, B, That]): That = self.++(that)(bf) + override def ++[B >: A, That](that: Iterator[B])(implicit bf: CanBuildFrom[This, B, That]): That = self.++(that)(bf) + override def map[B, That](f: A => B)(implicit bf: CanBuildFrom[This, B, That]): That = self.map(f)(bf) + override def flatMap[B, That](f: A => Traversable[B])(implicit bf: CanBuildFrom[This, B, That]): That = self.flatMap(f)(bf) override def filter(p: A => Boolean): This = self.filter(p) override def filterNot(p: A => Boolean): This = self.filterNot(p) override def remove(p: A => Boolean): This = self.filterNot(p) diff --git a/src/library/scala/collection/TraversableView.scala b/src/library/scala/collection/TraversableView.scala index 324a0038bd..b4362e2b6b 100644 --- a/src/library/scala/collection/TraversableView.scala +++ b/src/library/scala/collection/TraversableView.scala @@ -36,5 +36,9 @@ object TraversableView { def clear() {} } type Coll = TraversableView[_, C] forSome {type C <: Traversable[_]} - implicit def builderFactory[A]: BuilderFactory[A, TraversableView[A, Traversable[_]], Coll] = new BuilderFactory[A, TraversableView[A, Traversable[_]], Coll] { def apply(from: Coll) = new NoBuilder } + implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, TraversableView[A, Traversable[_]]] = + new CanBuildFrom[Coll, A, TraversableView[A, Traversable[_]]] { + def apply(from: Coll) = new NoBuilder + def apply() = new NoBuilder + } } diff --git a/src/library/scala/collection/TraversableViewLike.scala b/src/library/scala/collection/TraversableViewLike.scala index 9303e473fd..2f33776b74 100644 --- a/src/library/scala/collection/TraversableViewLike.scala +++ b/src/library/scala/collection/TraversableViewLike.scala @@ -24,7 +24,7 @@ import TraversableView.NoBuilder * @note Methods such as map/flatMap on this will not invoke the implicitly passed * Builder factory, but will return a new view directly, to preserve by-name behavior. * The new view is then cast to the factory's result type. - * This means that every BuilderFactory that takes a + * This means that every CanBuildFrom that takes a * View as its From type parameter must yield the same view (or a generic superclass of it) * as its result parameter. If that assumption is broken, cast errors might result. * @@ -42,7 +42,7 @@ self => protected def underlying: Coll - def force[B >: A, That](implicit bf: BuilderFactory[B, That, Coll]) = { + def force[B >: A, That](implicit bf: CanBuildFrom[Coll, B, That]) = { val b = bf(underlying) b ++= this b.result() @@ -143,23 +143,23 @@ self => protected def newDroppedWhile(p: A => Boolean): Transformed[A] = new DroppedWhile { val pred = p } protected def newTakenWhile(p: A => Boolean): Transformed[A] = new TakenWhile { val pred = p } - override def ++[B >: A, That](that: Traversable[B])(implicit bf: BuilderFactory[B, That, This]): That = { + override def ++[B >: A, That](that: Traversable[B])(implicit bf: CanBuildFrom[This, B, That]): That = { newAppended(that).asInstanceOf[That] // was: val b = bf(repr) // if (b.isInstanceOf[NoBuilder[_]]) newAppended(that).asInstanceOf[That] // else super.++[B, That](that)(bf) } - override def ++[B >: A, That](that: Iterator[B])(implicit bf: BuilderFactory[B, That, This]): That = ++[B, That](that.toStream) + override def ++[B >: A, That](that: Iterator[B])(implicit bf: CanBuildFrom[This, B, That]): That = ++[B, That](that.toStream) - override def map[B, That](f: A => B)(implicit bf: BuilderFactory[B, That, This]): That = { + override def map[B, That](f: A => B)(implicit bf: CanBuildFrom[This, B, That]): That = { newMapped(f).asInstanceOf[That] // was: val b = bf(repr) // if (b.isInstanceOf[NoBuilder[_]]) newMapped(f).asInstanceOf[That] // else super.map[B, That](f)(bf) } - override def flatMap[B, That](f: A => Traversable[B])(implicit bf: BuilderFactory[B, That, This]): That = { + override def flatMap[B, That](f: A => Traversable[B])(implicit bf: CanBuildFrom[This, B, That]): That = { newFlatMapped(f).asInstanceOf[That] // was: val b = bf(repr) // if (b.isInstanceOf[NoBuilder[_]]) newFlatMapped(f).asInstanceOf[That] diff --git a/src/library/scala/collection/Vector.scala b/src/library/scala/collection/Vector.scala index 3b616c887b..053cbfd74d 100644 --- a/src/library/scala/collection/Vector.scala +++ b/src/library/scala/collection/Vector.scala @@ -35,7 +35,10 @@ trait Vector[+A] extends Seq[A] object Vector extends SeqFactory[Vector] { override def empty[A]: Vector[A] = immutable.Vector.empty[A] - implicit def builderFactory[A]: BuilderFactory[A, Vector[A], Coll] = new VirtualBuilderFactory[A] + implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, Vector[A]] = + new GenericCanBuildFrom[A] { + def apply() = newBuilder[A] + } def newBuilder[A]: Builder[A, Vector[A]] = immutable.Vector.newBuilder[A] @deprecated("use collection.mutable.Vector instead") type Mutable[A] = scala.collection.mutable.Vector[A] diff --git a/src/library/scala/collection/VectorLike.scala b/src/library/scala/collection/VectorLike.scala index c0331d9758..79c07cda60 100644 --- a/src/library/scala/collection/VectorLike.scala +++ b/src/library/scala/collection/VectorLike.scala @@ -97,7 +97,7 @@ trait VectorLike[+A, +Repr] extends SeqLike[A, Repr] { self => override def reduceRight[B >: A](op: (A, B) => B): B = if (length > 0) foldr(0, length - 1, this(length - 1), op) else super.reduceRight(op) - override def zip[A1 >: A, B, That](that: Iterable[B])(implicit bf: BuilderFactory[(A1, B), That, Repr]): That = that match { + override def zip[A1 >: A, B, That](that: Iterable[B])(implicit bf: CanBuildFrom[Repr, (A1, B), That]): That = that match { case that: Vector[_] => val b = bf(repr) var i = 0 @@ -112,7 +112,7 @@ trait VectorLike[+A, +Repr] extends SeqLike[A, Repr] { self => super.zip[A1, B, That](that)(bf) } - override def zipWithIndex[A1 >: A, That](implicit bf: BuilderFactory[(A1, Int), That, Repr]): That = { + override def zipWithIndex[A1 >: A, That](implicit bf: CanBuildFrom[Repr, (A1, Int), That]): That = { val b = bf(repr) val len = length b.sizeHint(len) diff --git a/src/library/scala/collection/VectorView.scala b/src/library/scala/collection/VectorView.scala index 83705384be..2611d461c4 100644 --- a/src/library/scala/collection/VectorView.scala +++ b/src/library/scala/collection/VectorView.scala @@ -25,6 +25,14 @@ trait VectorView[+A, +Coll] extends VectorViewLike[A, Coll, VectorView[A, Coll]] object VectorView { type Coll = TraversableView[_, C] forSome {type C <: Traversable[_]} - implicit def builderFactory[A]: BuilderFactory[A, VectorView[A, Vector[_]], Coll] = new BuilderFactory[A, VectorView[A, Vector[_]], Coll] { def apply(from: Coll) = new NoBuilder } - implicit def arrBuilderFactory[A]: BuilderFactory[A, VectorView[A, Array[A]], TraversableView[_, Array[_]]] = new BuilderFactory[A, VectorView[A, Array[A]], TraversableView[_, Array[_]]] { def apply(from: TraversableView[_, Array[_]]) = new NoBuilder } + implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, VectorView[A, Vector[_]]] = + new CanBuildFrom[Coll, A, VectorView[A, Vector[_]]] { + def apply(from: Coll) = new NoBuilder + def apply() = new NoBuilder + } + implicit def arrCanBuildFrom[A]: CanBuildFrom[TraversableView[_, Array[_]], A, VectorView[A, Array[A]]] = + new CanBuildFrom[TraversableView[_, Array[_]], A, VectorView[A, Array[A]]] { + def apply(from: TraversableView[_, Array[_]]) = new NoBuilder + def apply() = new NoBuilder + } } diff --git a/src/library/scala/collection/generic/BitSetFactory.scala b/src/library/scala/collection/generic/BitSetFactory.scala index bfc8593a4d..1432fe5932 100644 --- a/src/library/scala/collection/generic/BitSetFactory.scala +++ b/src/library/scala/collection/generic/BitSetFactory.scala @@ -22,8 +22,9 @@ trait BitSetFactory[Coll <: BitSet with BitSetLike[Coll]] { def newBuilder: Builder[Int, Coll] = new AddingBuilder[Int, Coll](empty) def empty: Coll def apply(elems: Int*): Coll = (empty /: elems) (_ + _) - def bitsetBuilderFactory = new BuilderFactory[Int, Coll, Coll] { + def bitsetCanBuildFrom = new CanBuildFrom[Coll, Int, Coll] { def apply(from: Coll) = newBuilder + def apply() = newBuilder } } diff --git a/src/library/scala/collection/generic/BuilderFactory.scala b/src/library/scala/collection/generic/CanBuildFrom.scala index e377cd46e3..18f0bde2cb 100644 --- a/src/library/scala/collection/generic/BuilderFactory.scala +++ b/src/library/scala/collection/generic/CanBuildFrom.scala @@ -17,8 +17,13 @@ import mutable.Builder * * @since 2.8 */ -trait BuilderFactory[-Elem, +To, -From] { +trait CanBuildFrom[-From, -Elem, +To] { - /** Creates a new builder */ + /** Creates a new builder, using `from` as a prototype + * the resulting Builder will build the same kind of collection + */ def apply(from: From): Builder[Elem, To] + + /** Creates a new builder from scratch */ + def apply(): Builder[Elem, To] } diff --git a/src/library/scala/collection/generic/MapFactory.scala b/src/library/scala/collection/generic/MapFactory.scala index 813431b534..9e47412448 100644 --- a/src/library/scala/collection/generic/MapFactory.scala +++ b/src/library/scala/collection/generic/MapFactory.scala @@ -29,7 +29,8 @@ abstract class MapFactory[CC[A, B] <: Map[A, B] with MapLike[A, B, CC[A, B]]] { def apply[A, B](elems: (A, B)*): CC[A, B] = (newBuilder[A, B] ++= elems).result - class MapBuilderFactory[A, B] extends BuilderFactory[(A, B), CC[A, B], Coll] { + class MapCanBuildFrom[A, B] extends CanBuildFrom[Coll, (A, B), CC[A, B]] { def apply(from: Coll) = newBuilder[A, B] + def apply() = newBuilder } } diff --git a/src/library/scala/collection/generic/SetFactory.scala b/src/library/scala/collection/generic/SetFactory.scala index 8ed299ff6a..be864a45b1 100644 --- a/src/library/scala/collection/generic/SetFactory.scala +++ b/src/library/scala/collection/generic/SetFactory.scala @@ -24,7 +24,8 @@ abstract class SetFactory[CC[X] <: Set[X] with SetLike[X, CC[X]]] def newBuilder[A]: Builder[A, CC[A]] = new AddingBuilder[A, CC[A]](empty[A]) - def setBuilderFactory[A] = new BuilderFactory[A, CC[A], CC[_]] { + def setCanBuildFrom[A] = new CanBuildFrom[CC[_], A, CC[A]] { def apply(from: CC[_]) = newBuilder[A] + def apply() = newBuilder[A] } } diff --git a/src/library/scala/collection/generic/SortedMapFactory.scala b/src/library/scala/collection/generic/SortedMapFactory.scala index 2be68b3ca9..5bba735fef 100644 --- a/src/library/scala/collection/generic/SortedMapFactory.scala +++ b/src/library/scala/collection/generic/SortedMapFactory.scala @@ -28,7 +28,8 @@ abstract class SortedMapFactory[CC[A, B] <: SortedMap[A, B] with SortedMapLike[A def apply[A, B](elems: (A, B)*)(implicit ord: Ordering[A]): CC[A, B] = (newBuilder[A, B](ord) ++= elems).result - class SortedMapBuilderFactory[A, B](implicit ord: Ordering[A]) extends BuilderFactory[(A, B), CC[A, B], Coll] { + class SortedMapCanBuildFrom[A, B](implicit ord: Ordering[A]) extends CanBuildFrom[Coll, (A, B), CC[A, B]] { def apply(from: Coll) = newBuilder[A, B](ord) + def apply() = newBuilder[A, B] } } diff --git a/src/library/scala/collection/generic/SortedSetFactory.scala b/src/library/scala/collection/generic/SortedSetFactory.scala index dc98f37579..1c7ca885aa 100644 --- a/src/library/scala/collection/generic/SortedSetFactory.scala +++ b/src/library/scala/collection/generic/SortedSetFactory.scala @@ -27,9 +27,10 @@ abstract class SortedSetFactory[CC[A] <: SortedSet[A] with SortedSetLike[A, CC[A def apply[A](elems: A*)(implicit ord: Ordering[A]): CC[A] = (newBuilder[A](ord) ++= elems).result - implicit def newBuilderFactory[A](implicit ord : Ordering[A]) : BuilderFactory[A, CC[A], Coll] = new SortedSetBuilderFactory()(ord); + implicit def newCanBuildFrom[A](implicit ord : Ordering[A]) : CanBuildFrom[Coll, A, CC[A]] = new SortedSetCanBuildFrom()(ord); - class SortedSetBuilderFactory[A](implicit ord: Ordering[A]) extends BuilderFactory[A, CC[A], Coll] { + class SortedSetCanBuildFrom[A](implicit ord: Ordering[A]) extends CanBuildFrom[Coll, A, CC[A]] { def apply(from: Coll) = newBuilder[A](ord) + def apply() = newBuilder[A](ord) } } diff --git a/src/library/scala/collection/generic/TraversableFactory.scala b/src/library/scala/collection/generic/TraversableFactory.scala index a43e607989..f5d548efa3 100644 --- a/src/library/scala/collection/generic/TraversableFactory.scala +++ b/src/library/scala/collection/generic/TraversableFactory.scala @@ -18,7 +18,7 @@ package generic abstract class TraversableFactory[CC[X] <: Traversable[X] with GenericTraversableTemplate[X, CC]] extends GenericCompanion[CC] { - class VirtualBuilderFactory[A] extends BuilderFactory[A, CC[A], CC[_]] { + abstract class GenericCanBuildFrom[A] extends CanBuildFrom[CC[_], A, CC[A]] { def apply(from: Coll) = from.genericBuilder[A] } diff --git a/src/library/scala/collection/immutable/BitSet.scala b/src/library/scala/collection/immutable/BitSet.scala index 1d81618a92..735e950c96 100644 --- a/src/library/scala/collection/immutable/BitSet.scala +++ b/src/library/scala/collection/immutable/BitSet.scala @@ -60,7 +60,7 @@ object BitSet extends BitSetFactory[BitSet] { /** The empty bitset */ val empty: BitSet = new BitSet1(0L) - implicit def builderFactory: BuilderFactory[Int, BitSet, BitSet] = bitsetBuilderFactory + implicit def canBuildFrom: CanBuildFrom[BitSet, Int, BitSet] = bitsetCanBuildFrom /** A bitset containing all the bits in an array */ def fromArray(elems: Array[Long]): BitSet = { diff --git a/src/library/scala/collection/immutable/HashMap.scala b/src/library/scala/collection/immutable/HashMap.scala index d307241f2a..64608d163f 100644 --- a/src/library/scala/collection/immutable/HashMap.scala +++ b/src/library/scala/collection/immutable/HashMap.scala @@ -183,7 +183,7 @@ class HashMap[A, +B] extends Map[A,B] with MapLike[A, B, HashMap[A, B]] with mut * @since 2.3 */ object HashMap extends ImmutableMapFactory[HashMap] { - implicit def builderFactory[A, B]: BuilderFactory[(A, B), HashMap[A, B], Coll] = new MapBuilderFactory[A, B] + implicit def canBuildFrom[A, B]: CanBuildFrom[Coll, (A, B), HashMap[A, B]] = new MapCanBuildFrom[A, B] def empty[A, B]: HashMap[A, B] = new HashMap } diff --git a/src/library/scala/collection/immutable/HashSet.scala b/src/library/scala/collection/immutable/HashSet.scala index 7d31cadf1c..93b9678751 100644 --- a/src/library/scala/collection/immutable/HashSet.scala +++ b/src/library/scala/collection/immutable/HashSet.scala @@ -141,7 +141,7 @@ class HashSet[A] extends Set[A] * @since 2.3 */ object HashSet extends SetFactory[HashSet] { - implicit def builderFactory[A]: BuilderFactory[A, HashSet[A], Coll] = setBuilderFactory[A] + implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, HashSet[A]] = setCanBuildFrom[A] override def empty[A]: HashSet[A] = new HashSet } diff --git a/src/library/scala/collection/immutable/Iterable.scala b/src/library/scala/collection/immutable/Iterable.scala index 29615a0555..c3c67f5953 100644 --- a/src/library/scala/collection/immutable/Iterable.scala +++ b/src/library/scala/collection/immutable/Iterable.scala @@ -37,7 +37,10 @@ trait Iterable[+A] extends Traversable[A] * @since 2.8 */ object Iterable extends TraversableFactory[Iterable] { - implicit def builderFactory[A]: BuilderFactory[A, Iterable[A], Coll] = new VirtualBuilderFactory[A] + implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, Iterable[A]] = + new GenericCanBuildFrom[A] { + def apply() = newBuilder[A] + } def newBuilder[A]: Builder[A, Iterable[A]] = new mutable.ListBuffer } diff --git a/src/library/scala/collection/immutable/LinearSeq.scala b/src/library/scala/collection/immutable/LinearSeq.scala index 09ef071ca4..af5b26b38b 100644 --- a/src/library/scala/collection/immutable/LinearSeq.scala +++ b/src/library/scala/collection/immutable/LinearSeq.scala @@ -31,6 +31,9 @@ trait LinearSeq[+A] extends Seq[A] * @since 2.8 */ object LinearSeq extends SeqFactory[LinearSeq] { - implicit def builderFactory[A]: BuilderFactory[A, LinearSeq[A], Coll] = new VirtualBuilderFactory[A] + implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, LinearSeq[A]] = + new GenericCanBuildFrom[A] { + def apply() = newBuilder[A] + } def newBuilder[A]: Builder[A, LinearSeq[A]] = new mutable.ListBuffer } diff --git a/src/library/scala/collection/immutable/List.scala b/src/library/scala/collection/immutable/List.scala index b7a2908536..79be24cb3e 100644 --- a/src/library/scala/collection/immutable/List.scala +++ b/src/library/scala/collection/immutable/List.scala @@ -147,7 +147,7 @@ sealed abstract class List[+A] extends LinearSeq[A] /** Create a new list which contains all elements of this list * followed by all elements of Traversable `that' */ - override def ++[B >: A, That](that: Traversable[B])(implicit bf: BuilderFactory[B, That, List[A]]): That = { + override def ++[B >: A, That](that: Traversable[B])(implicit bf: CanBuildFrom[List[A], B, That]): That = { val b = bf(this) if (b.isInstanceOf[ListBuffer[_]]) (this ::: that.toList).asInstanceOf[That] else super.++(that) @@ -156,7 +156,7 @@ sealed abstract class List[+A] extends LinearSeq[A] /** Create a new list which contains all elements of this list * followed by all elements of Iterator `that' */ - override def ++[B >: A, That](that: Iterator[B])(implicit bf: BuilderFactory[B, That, List[A]]): That = + override def ++[B >: A, That](that: Iterator[B])(implicit bf: CanBuildFrom[List[A], B, That]): That = this ++ that.toList /** Overrides the method in Iterable for efficiency. @@ -502,7 +502,11 @@ object List extends SeqFactory[List] { import scala.collection.{Iterable, Seq, Vector} - implicit def builderFactory[A]: BuilderFactory[A, List[A], Coll] = new VirtualBuilderFactory[A] + implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, List[A]] = + new GenericCanBuildFrom[A] { + def apply() = newBuilder[A] + } + def newBuilder[A]: Builder[A, List[A]] = new ListBuffer[A] override def empty[A]: List[A] = Nil diff --git a/src/library/scala/collection/immutable/ListMap.scala b/src/library/scala/collection/immutable/ListMap.scala index 3169aaf608..f56993241d 100644 --- a/src/library/scala/collection/immutable/ListMap.scala +++ b/src/library/scala/collection/immutable/ListMap.scala @@ -19,8 +19,8 @@ import generic._ * @since 1 */ object ListMap extends ImmutableMapFactory[ListMap] { - implicit def builderFactory[A, B]: BuilderFactory[(A, B), ListMap[A, B], Coll] = - new MapBuilderFactory[A, B] + implicit def canBuildFrom[A, B]: CanBuildFrom[Coll, (A, B), ListMap[A, B]] = + new MapCanBuildFrom[A, B] def empty[A, B]: ListMap[A, B] = new ListMap } diff --git a/src/library/scala/collection/immutable/ListSet.scala b/src/library/scala/collection/immutable/ListSet.scala index 46186b2c77..7767e42224 100644 --- a/src/library/scala/collection/immutable/ListSet.scala +++ b/src/library/scala/collection/immutable/ListSet.scala @@ -19,7 +19,7 @@ import generic._ * @since 1 */ object ListSet extends SetFactory[ListSet] { - implicit def builderFactory[A]: BuilderFactory[A, ListSet[A], Coll] = setBuilderFactory[A] + implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, ListSet[A]] = setCanBuildFrom[A] override def empty[A] = new ListSet[A] } diff --git a/src/library/scala/collection/immutable/Map.scala b/src/library/scala/collection/immutable/Map.scala index 1f5b35c1c2..e1d0abb928 100644 --- a/src/library/scala/collection/immutable/Map.scala +++ b/src/library/scala/collection/immutable/Map.scala @@ -42,7 +42,7 @@ trait Map[A, +B] extends Iterable[(A, B)] * @since 1 */ object Map extends ImmutableMapFactory[Map] { - implicit def builderFactory[A, B]: BuilderFactory[(A, B), Map[A, B], Coll] = new MapBuilderFactory[A, B] + implicit def canBuildFrom[A, B]: CanBuildFrom[Coll, (A, B), Map[A, B]] = new MapCanBuildFrom[A, B] def empty[A, B]: Map[A, B] = new EmptyMap[A, B] diff --git a/src/library/scala/collection/immutable/MapLike.scala b/src/library/scala/collection/immutable/MapLike.scala index 4139beace7..8ea7fc2a97 100644 --- a/src/library/scala/collection/immutable/MapLike.scala +++ b/src/library/scala/collection/immutable/MapLike.scala @@ -91,7 +91,7 @@ self => * @param f A function over keys and values * @return the updated map */ - def transform[C, That](f: (A, B) => C)(implicit bf: BuilderFactory[(A, C), That, This]): That = { + def transform[C, That](f: (A, B) => C)(implicit bf: CanBuildFrom[This, (A, C), That]): That = { val b = bf(repr) for ((key, value) <- this) b += ((key, f(key, value))) b.result diff --git a/src/library/scala/collection/immutable/Seq.scala b/src/library/scala/collection/immutable/Seq.scala index 6091971ffd..3b8bb07ba0 100644 --- a/src/library/scala/collection/immutable/Seq.scala +++ b/src/library/scala/collection/immutable/Seq.scala @@ -31,6 +31,10 @@ trait Seq[+A] extends Iterable[A] * @since 2.8 */ object Seq extends SeqFactory[Seq] { - implicit def builderFactory[A]: BuilderFactory[A, Seq[A], Coll] = new VirtualBuilderFactory[A] + implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, Seq[A]] = + new GenericCanBuildFrom[A] { + def apply() = newBuilder[A] + } + def newBuilder[A]: Builder[A, Seq[A]] = new mutable.ListBuffer } diff --git a/src/library/scala/collection/immutable/Set.scala b/src/library/scala/collection/immutable/Set.scala index 58b3950edf..cc935afe93 100644 --- a/src/library/scala/collection/immutable/Set.scala +++ b/src/library/scala/collection/immutable/Set.scala @@ -40,7 +40,7 @@ trait Set[A] extends Iterable[A] } object Set extends SetFactory[Set] { - implicit def builderFactory[A]: BuilderFactory[A, Set[A], Coll] = setBuilderFactory[A] + implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, Set[A]] = setCanBuildFrom[A] override def empty[A]: Set[A] = new EmptySet[A] private val hashSeed = "Set".hashCode diff --git a/src/library/scala/collection/immutable/SortedMap.scala b/src/library/scala/collection/immutable/SortedMap.scala index f2fd591417..5d0806c5e3 100644 --- a/src/library/scala/collection/immutable/SortedMap.scala +++ b/src/library/scala/collection/immutable/SortedMap.scala @@ -72,6 +72,6 @@ trait SortedMap[A, +B] extends Map[A, B] * @since 2.4 */ object SortedMap extends ImmutableSortedMapFactory[SortedMap] { - implicit def builderFactory[A, B](implicit ord: Ordering[A]): BuilderFactory[(A, B), SortedMap[A, B], Coll] = new SortedMapBuilderFactory[A, B] + implicit def canBuildFrom[A, B](implicit ord: Ordering[A]): CanBuildFrom[Coll, (A, B), SortedMap[A, B]] = new SortedMapCanBuildFrom[A, B] def empty[A, B](implicit ord: Ordering[A]): SortedMap[A, B] = TreeMap.empty[A, B] } diff --git a/src/library/scala/collection/immutable/SortedSet.scala b/src/library/scala/collection/immutable/SortedSet.scala index 126b751164..6fa233cad7 100644 --- a/src/library/scala/collection/immutable/SortedSet.scala +++ b/src/library/scala/collection/immutable/SortedSet.scala @@ -31,6 +31,6 @@ trait SortedSet[A] extends Set[A] with scala.collection.SortedSet[A] with Sorted * @since 2.4 */ object SortedSet extends ImmutableSortedSetFactory[SortedSet] { - implicit def builderFactory[A](implicit ord: Ordering[A]): BuilderFactory[A, SortedSet[A], Coll] = new SortedSetBuilderFactory[A] + implicit def canBuildFrom[A](implicit ord: Ordering[A]): CanBuildFrom[Coll, A, SortedSet[A]] = new SortedSetCanBuildFrom[A] def empty[A](implicit ord: Ordering[A]): SortedSet[A] = TreeSet.empty[A] } diff --git a/src/library/scala/collection/immutable/Stream.scala b/src/library/scala/collection/immutable/Stream.scala index bcf8076a1c..9550aec2ef 100644 --- a/src/library/scala/collection/immutable/Stream.scala +++ b/src/library/scala/collection/immutable/Stream.scala @@ -117,7 +117,7 @@ self => * then StreamBuilder will be chosen for the implicit. * we recognize that fact and optimize to get more laziness. */ - override def ++[B >: A, That](that: Traversable[B])(implicit bf: BuilderFactory[B, That, Stream[A]]): That = { + override def ++[B >: A, That](that: Traversable[B])(implicit bf: CanBuildFrom[Stream[A], B, That]): That = { // we assume there is no other builder factory on streams and therefore know that That = Stream[A] (if (isEmpty) that.toStream else new Stream.Cons(head, (tail ++ that).asInstanceOf[Stream[A]])).asInstanceOf[That] @@ -126,7 +126,7 @@ self => /** Create a new stream which contains all elements of this stream * followed by all elements of Iterator `that' */ - override def++[B >: A, That](that: Iterator[B])(implicit bf: BuilderFactory[B, That, Stream[A]]): That = + override def++[B >: A, That](that: Iterator[B])(implicit bf: CanBuildFrom[Stream[A], B, That]): That = this ++ that.toStream /** Returns the stream resulting from applying the given function @@ -136,7 +136,7 @@ self => * @return <code>f(a<sub>0</sub>), ..., f(a<sub>n</sub>)</code> if this * sequence is <code>a<sub>0</sub>, ..., a<sub>n</sub></code>. */ - override final def map[B, That](f: A => B)(implicit bf: BuilderFactory[B, That, Stream[A]]): That = { + override final def map[B, That](f: A => B)(implicit bf: CanBuildFrom[Stream[A], B, That]): That = { (if (isEmpty) Stream.Empty else new Stream.Cons(f(head), (tail map f).asInstanceOf[Stream[B]])).asInstanceOf[That] } @@ -148,7 +148,7 @@ self => * @return <code>f(a<sub>0</sub>) ::: ... ::: f(a<sub>n</sub>)</code> if * this stream is <code>[a<sub>0</sub>, ..., a<sub>n</sub>]</code>. */ - override final def flatMap[B, That](f: A => Traversable[B])(implicit bf: BuilderFactory[B, That, Stream[A]]): That = { + override final def flatMap[B, That](f: A => Traversable[B])(implicit bf: CanBuildFrom[Stream[A], B, That]): That = { // we assume there is no other builder factory on streams and therefore know that That = Stream[B] // optimization: drop A's for which f yields no B var rest = this @@ -218,7 +218,7 @@ self => * <code>Stream(a<sub>0</sub>, ..., a<sub>m</sub>) * zip Stream(b<sub>0</sub>, ..., b<sub>n</sub>)</code> is invoked. */ - override final def zip[A1 >: A, B, That](that: Iterable[B])(implicit bf: BuilderFactory[(A1, B), That, Stream[A]]): That = { + override final def zip[A1 >: A, B, That](that: Iterable[B])(implicit bf: CanBuildFrom[Stream[A], (A1, B), That]): That = { // we assume there is no other builder factory on streams and therefore know that That = Stream[(A1, B)] (if (this.isEmpty || that.isEmpty) Stream.Empty else new Stream.Cons((this.head, that.head), (this.tail zip that.tail).asInstanceOf[Stream[(A1, B)]])).asInstanceOf[That] @@ -227,7 +227,7 @@ self => /** Zips this iterable with its indices. `s.zipWithIndex` is equivalent to * `s zip s.indices` */ - override def zipWithIndex[A1 >: A, That](implicit bf: BuilderFactory[(A1, Int), That, Stream[A]]): That = + override def zipWithIndex[A1 >: A, That](implicit bf: CanBuildFrom[Stream[A], (A1, Int), That]): That = this.zip[A1, Int, That](Stream.from(0)) /** Write all defined elements of this iterable into given string builder. @@ -349,12 +349,12 @@ self => /** Returns a new sequence of given length containing the elements of this sequence followed by zero * or more occurrences of given elements. */ - override def padTo[B >: A, That](len: Int, elem: B)(implicit bf: BuilderFactory[B, That, Stream[A]]): That = { + override def padTo[B >: A, That](len: Int, elem: B)(implicit bf: CanBuildFrom[Stream[A], B, That]): That = { def loop(len: Int, these: Stream[A]): Stream[B] = if (these.isEmpty) Stream.fill(len)(elem) else new Stream.Cons(these.head, loop(len - 1, these.tail)) loop(len, this).asInstanceOf[That] -// was: if (bf.isInstanceOf[Stream.StreamBuilderFactory[_]]) loop(len, this).asInstanceOf[That] +// was: if (bf.isInstanceOf[Stream.StreamCanBuildFrom[_]]) loop(len, this).asInstanceOf[That] // else super.padTo(len, elem) } @@ -404,13 +404,16 @@ object Stream extends SeqFactory[Stream] { * @note Methods such as map/flatMap will not invoke the Builder factory, * but will return a new stream directly, to preserve laziness. * The new stream is then cast to the factory's result type. - * This means that every BuilderFactory that takes a + * This means that every CanBuildFrom that takes a * Stream as its From type parameter must yield a stream as its result parameter. * If that assumption is broken, cast errors might result. */ - class StreamBuilderFactory[A] extends VirtualBuilderFactory[A] + class StreamCanBuildFrom[A] extends GenericCanBuildFrom[A] { + def apply() = newBuilder[A] + } + - implicit def builderFactory[A]: BuilderFactory[A, Stream[A], Coll] = new StreamBuilderFactory[A] + implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, Stream[A]] = new StreamCanBuildFrom[A] /** Creates a new builder for a stream */ def newBuilder[A]: Builder[A, Stream[A]] = new StreamBuilder[A] @@ -419,7 +422,7 @@ object Stream extends SeqFactory[Stream] { /** A builder for streams * @note: This builder is lazy only in the sense that it does not go downs the spine - * of traversables taht are added as a whole. If more layzness can be achieved, + * of traversables that are added as a whole. If more laziness can be achieved, * this builder should be bypassed. */ class StreamBuilder[A] extends scala.collection.mutable.LazyBuilder[A, Stream[A]] { diff --git a/src/library/scala/collection/immutable/Traversable.scala b/src/library/scala/collection/immutable/Traversable.scala index 8309e30302..3d337c1992 100644 --- a/src/library/scala/collection/immutable/Traversable.scala +++ b/src/library/scala/collection/immutable/Traversable.scala @@ -37,7 +37,9 @@ trait Traversable[+A] extends scala.collection.Traversable[A] * @since 2.8 */ object Traversable extends TraversableFactory[Traversable] { - implicit def builderFactory[A]: BuilderFactory[A, Traversable[A], Coll] = - new VirtualBuilderFactory[A] + implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, Traversable[A]] = + new GenericCanBuildFrom[A] { + def apply() = newBuilder[A] + } def newBuilder[A]: Builder[A, Traversable[A]] = new mutable.ListBuffer } diff --git a/src/library/scala/collection/immutable/TreeMap.scala b/src/library/scala/collection/immutable/TreeMap.scala index 773f805f36..9d3f93cb7d 100644 --- a/src/library/scala/collection/immutable/TreeMap.scala +++ b/src/library/scala/collection/immutable/TreeMap.scala @@ -21,7 +21,7 @@ import mutable.Builder */ object TreeMap extends ImmutableSortedMapFactory[TreeMap] { def empty[A, B](implicit ord: Ordering[A]) = new TreeMap[A, B]()(ord) - implicit def builderFactory[A, B](implicit ord: Ordering[A]): BuilderFactory[(A, B), TreeMap[A, B], Coll] = new SortedMapBuilderFactory[A, B] + implicit def canBuildFrom[A, B](implicit ord: Ordering[A]): CanBuildFrom[Coll, (A, B), TreeMap[A, B]] = new SortedMapCanBuildFrom[A, B] private def make[A, B](s: Int, t: RedBlack[A]#Tree[B])(implicit ord: Ordering[A]) = new TreeMap[A, B](s, t)(ord) } diff --git a/src/library/scala/collection/immutable/Vector.scala b/src/library/scala/collection/immutable/Vector.scala index 4b0cecf582..dd9a2fefcc 100644 --- a/src/library/scala/collection/immutable/Vector.scala +++ b/src/library/scala/collection/immutable/Vector.scala @@ -36,8 +36,10 @@ trait Vector[+A] extends Seq[A] * @since 2.8 */ object Vector extends SeqFactory[Vector] { - implicit def builderFactory[A]: BuilderFactory[A, Vector[A], Coll] = - new VirtualBuilderFactory[A] + implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, Vector[A]] = + new GenericCanBuildFrom[A] { + def apply() = newBuilder[A] + } override def empty[A] = NewVector.empty[A] def newBuilder[A]: Builder[A, Vector[A]] = NewVector.newBuilder[A] } @@ -55,9 +57,11 @@ trait NewVector[+A] extends Vector[A] object NewVector extends SeqFactory[NewVector] { - private[immutable] val bf = new VirtualBuilderFactory[Nothing] - implicit def builderFactory[A]: BuilderFactory[A, NewVector[A], Coll] = - bf.asInstanceOf[BuilderFactory[A, NewVector[A], Coll]] + private[immutable] val bf = new GenericCanBuildFrom[Nothing] { + def apply() = newBuilder[Nothing] + } + implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, NewVector[A]] = + bf.asInstanceOf[CanBuildFrom[Coll, A, NewVector[A]]] def newBuilder[A]: Builder[A, NewVector[A]] = new NewVectorBuilder[A] override def empty[A]: NewVector[A] = new NewVectorImpl[A](0, 0, 0) @@ -107,17 +111,17 @@ private class NewVectorImpl[+A](startIndex: Int, endIndex: Int, focus: Int) exte // SeqLike api - override def updated[B >: A, That](index: Int, elem: B)(implicit bf: BuilderFactory[B, That, NewVector[A]]): That = { + override def updated[B >: A, That](index: Int, elem: B)(implicit bf: CanBuildFrom[NewVector[A], B, That]): That = { // just ignore bf updateAt(index, elem).asInstanceOf[That] } - override def +:[B >: A, That](elem: B)(implicit bf: BuilderFactory[B, That, NewVector[A]]): That = { + override def +:[B >: A, That](elem: B)(implicit bf: CanBuildFrom[NewVector[A], B, That]): That = { // just ignore bf appendFront(elem).asInstanceOf[That] } - override def :+[B >: A, That](elem: B)(implicit bf: BuilderFactory[B, That, NewVector[A]]): That = { + override def :+[B >: A, That](elem: B)(implicit bf: CanBuildFrom[NewVector[A], B, That]): That = { // just ignore bf appendBack(elem).asInstanceOf[That] } diff --git a/src/library/scala/collection/interfaces/IterableMethods.scala b/src/library/scala/collection/interfaces/IterableMethods.scala index e4f502dbe4..fe44c0a380 100644 --- a/src/library/scala/collection/interfaces/IterableMethods.scala +++ b/src/library/scala/collection/interfaces/IterableMethods.scala @@ -27,9 +27,9 @@ trait IterableMethods[+A, +This <: IterableLike[A, This] with Iterable[A]] exten def sameElements[B >: A](that: Iterable[B]): Boolean def sortWith(lt: (A, A) => Boolean)(implicit m: ClassManifest[A @uncheckedVariance]): This def takeRight(n: Int): Iterable[A] - def zipAll[B, A1 >: A, That](that: Iterable[B], e1: A1, e2: B)(implicit bf: BuilderFactory[(A1, B), That, This]): That - def zipWithIndex[A1 >: A, That](implicit bf: BuilderFactory[(A1, Int), That, This]): That - def zip[A1 >: A, B, That](that: Iterable[B])(implicit bf: BuilderFactory[(A1, B), That, This]): That + def zipAll[B, A1 >: A, That](that: Iterable[B], e1: A1, e2: B)(implicit bf: CanBuildFrom[This, (A1, B), That]): That + def zipWithIndex[A1 >: A, That](implicit bf: CanBuildFrom[This, (A1, Int), That]): That + def zip[A1 >: A, B, That](that: Iterable[B])(implicit bf: CanBuildFrom[This, (A1, B), That]): That override def view: IterableView[A, This] override def view(from: Int, until: Int): IterableView[A, This] diff --git a/src/library/scala/collection/interfaces/SeqMethods.scala b/src/library/scala/collection/interfaces/SeqMethods.scala index a595d101fa..8256c5304c 100644 --- a/src/library/scala/collection/interfaces/SeqMethods.scala +++ b/src/library/scala/collection/interfaces/SeqMethods.scala @@ -41,8 +41,8 @@ trait SeqMethods[+A, +This <: SeqLike[A, This] with Seq[A]] extends IterableMeth def lastIndexWhere(p: A => Boolean): Int def lastIndexWhere(p: A => Boolean, end: Int): Int def lengthCompare(len: Int): Int - def padTo[B >: A, That](len: Int, elem: B)(implicit bf: BuilderFactory[B, That, This]): That - def patch[B >: A, That](from: Int, patch: Seq[B], replaced: Int)(implicit bf: BuilderFactory[B, That, This]): That + def padTo[B >: A, That](len: Int, elem: B)(implicit bf: CanBuildFrom[This, B, That]): That + def patch[B >: A, That](from: Int, patch: Seq[B], replaced: Int)(implicit bf: CanBuildFrom[This, B, That]): That def prefixLength(p: A => Boolean): Int def removeDuplicates: This def reverse: This @@ -51,7 +51,7 @@ trait SeqMethods[+A, +This <: SeqLike[A, This] with Seq[A]] extends IterableMeth def slice(from: Int): Seq[A] def startsWith[B](that: Seq[B]): Boolean def startsWith[B](that: Seq[B], offset: Int): Boolean - def union[B >: A, That](that: Seq[B])(implicit bf: BuilderFactory[B, That, This]): That + def union[B >: A, That](that: Seq[B])(implicit bf: CanBuildFrom[This, B, That]): That override def view: SeqView[A, This] override def view(from: Int, until: Int): SeqView[A, This] diff --git a/src/library/scala/collection/interfaces/TraversableMethods.scala b/src/library/scala/collection/interfaces/TraversableMethods.scala index ffedb10476..b7801fea0f 100644 --- a/src/library/scala/collection/interfaces/TraversableMethods.scala +++ b/src/library/scala/collection/interfaces/TraversableMethods.scala @@ -22,13 +22,13 @@ trait TraversableMethods[+A, +This <: TraversableLike[A, This] with Traversable[ def foreach[U](f: A => U): Unit // maps/iteration - def flatMap[B, That](f: A => Traversable[B])(implicit bf: BuilderFactory[B, That, This]): That - def map[B, That](f: A => B)(implicit bf: BuilderFactory[B, That, This]): That - def filterMap[B, That](pf: PartialFunction[Any, B])(implicit bf: BuilderFactory[B, That, This]): That + def flatMap[B, That](f: A => Traversable[B])(implicit bf: CanBuildFrom[This, B, That]): That + def map[B, That](f: A => B)(implicit bf: CanBuildFrom[This, B, That]): That + def filterMap[B, That](pf: PartialFunction[Any, B])(implicit bf: CanBuildFrom[This, B, That]): That // new collections - def ++[B >: A, That](that: Iterator[B])(implicit bf: BuilderFactory[B, That, This]): That - def ++[B >: A, That](that: Traversable[B])(implicit bf: BuilderFactory[B, That, This]): That + def ++[B >: A, That](that: Iterator[B])(implicit bf: CanBuildFrom[This, B, That]): That + def ++[B >: A, That](that: Traversable[B])(implicit bf: CanBuildFrom[This, B, That]): That def copyToArray[B >: A](xs: Array[B], start: Int): Unit def copyToArray[B >: A](xs: Array[B], start: Int, len: Int): Unit def copyToBuffer[B >: A](dest: Buffer[B]): Unit diff --git a/src/library/scala/collection/mutable/ArrayBuffer.scala b/src/library/scala/collection/mutable/ArrayBuffer.scala index f5437d4494..3e865c069f 100644 --- a/src/library/scala/collection/mutable/ArrayBuffer.scala +++ b/src/library/scala/collection/mutable/ArrayBuffer.scala @@ -168,8 +168,10 @@ class ArrayBuffer[A](override protected val initialSize: Int) * @since 2.8 */ object ArrayBuffer extends SeqFactory[ArrayBuffer] { - implicit def builderFactory[A]: BuilderFactory[A, ArrayBuffer[A], Coll] = - new VirtualBuilderFactory[A] + implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, ArrayBuffer[A]] = + new GenericCanBuildFrom[A] { + def apply() = newBuilder[A] + } def newBuilder[A]: Builder[A, ArrayBuffer[A]] = new ArrayBuffer[A] } diff --git a/src/library/scala/collection/mutable/BitSet.scala b/src/library/scala/collection/mutable/BitSet.scala index cedad70488..cdec8c90b4 100644 --- a/src/library/scala/collection/mutable/BitSet.scala +++ b/src/library/scala/collection/mutable/BitSet.scala @@ -91,5 +91,5 @@ class BitSet(protected var elems: Array[Long]) extends Set[Int] /** A factory object for mutable bitsets */ object BitSet extends BitSetFactory[BitSet] { def empty: BitSet = new BitSet - implicit def builderFactory: BuilderFactory[Int, BitSet, BitSet] = bitsetBuilderFactory + implicit def canBuildFrom: CanBuildFrom[BitSet, Int, BitSet] = bitsetCanBuildFrom } diff --git a/src/library/scala/collection/mutable/Buffer.scala b/src/library/scala/collection/mutable/Buffer.scala index 59da5bbd83..213a93aa5b 100644 --- a/src/library/scala/collection/mutable/Buffer.scala +++ b/src/library/scala/collection/mutable/Buffer.scala @@ -34,7 +34,10 @@ trait Buffer[A] extends Seq[A] /** Factory object for <code>Buffer</code> trait. */ object Buffer extends SeqFactory[Buffer] { - implicit def builderFactory[A]: BuilderFactory[A, Buffer[A], Coll] = new VirtualBuilderFactory[A] + implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, Buffer[A]] = + new GenericCanBuildFrom[A] { + def apply() = newBuilder[A] + } def newBuilder[A]: Builder[A, Buffer[A]] = new ArrayBuffer } diff --git a/src/library/scala/collection/mutable/DoubleLinkedList.scala b/src/library/scala/collection/mutable/DoubleLinkedList.scala index 1c5d7211c0..a47ed40c54 100644 --- a/src/library/scala/collection/mutable/DoubleLinkedList.scala +++ b/src/library/scala/collection/mutable/DoubleLinkedList.scala @@ -32,8 +32,10 @@ class DoubleLinkedList[A](_elem: A, _next: DoubleLinkedList[A]) extends LinearSe } object DoubleLinkedList extends SeqFactory[DoubleLinkedList] { - implicit def builderFactory[A]: BuilderFactory[A, DoubleLinkedList[A], Coll] = //new BuilderFactory[A, DoubleLinkedList[A], Coll] { def apply(from: Coll) = from.traversableBuilder[A] } - new VirtualBuilderFactory[A] + implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, DoubleLinkedList[A]] = //new CanBuildFrom[Coll, A, DoubleLinkedList[A]] { : Coll) = from.traversableBuilder[A] } + new GenericCanBuildFrom[A] { + def apply() = newBuilder[A] + } def newBuilder[A]: Builder[A, DoubleLinkedList[A]] = new Builder[A, DoubleLinkedList[A]] { var current: DoubleLinkedList[A] = _ diff --git a/src/library/scala/collection/mutable/GenericArray.scala b/src/library/scala/collection/mutable/GenericArray.scala index 9194d7f39c..fe016908bf 100644 --- a/src/library/scala/collection/mutable/GenericArray.scala +++ b/src/library/scala/collection/mutable/GenericArray.scala @@ -68,7 +68,10 @@ extends Vector[A] } object GenericArray extends SeqFactory[GenericArray] { - implicit def builderFactory[A]: BuilderFactory[A, GenericArray[A], Coll] = new VirtualBuilderFactory[A] + implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, GenericArray[A]] = + new GenericCanBuildFrom[A] { + def apply() = newBuilder[A] + } def newBuilder[A]: Builder[A, GenericArray[A]] = new ArrayBuffer[A] mapResult { buf => val result = new GenericArray[A](buf.length) diff --git a/src/library/scala/collection/mutable/HashMap.scala b/src/library/scala/collection/mutable/HashMap.scala index bef02ebad4..2591557c78 100644 --- a/src/library/scala/collection/mutable/HashMap.scala +++ b/src/library/scala/collection/mutable/HashMap.scala @@ -67,6 +67,6 @@ class HashMap[A, B] extends Map[A, B] * @version 2.8 */ object HashMap extends MutableMapFactory[HashMap] { - implicit def builderFactory[A, B]: BuilderFactory[(A, B), HashMap[A, B], Coll] = new MapBuilderFactory[A, B] + implicit def canBuildFrom[A, B]: CanBuildFrom[Coll, (A, B), HashMap[A, B]] = new MapCanBuildFrom[A, B] def empty[A, B]: HashMap[A, B] = new HashMap[A, B] } diff --git a/src/library/scala/collection/mutable/HashSet.scala b/src/library/scala/collection/mutable/HashSet.scala index 536fd638b5..9f24a0b341 100644 --- a/src/library/scala/collection/mutable/HashSet.scala +++ b/src/library/scala/collection/mutable/HashSet.scala @@ -55,7 +55,7 @@ class HashSet[A] extends Set[A] /** Factory object for `HashSet` class */ object HashSet extends SetFactory[HashSet] { - implicit def builderFactory[A]: BuilderFactory[A, HashSet[A], Coll] = setBuilderFactory[A] + implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, HashSet[A]] = setCanBuildFrom[A] override def empty[A]: HashSet[A] = new HashSet[A] } diff --git a/src/library/scala/collection/mutable/Iterable.scala b/src/library/scala/collection/mutable/Iterable.scala index 13685b2376..40195623b8 100644 --- a/src/library/scala/collection/mutable/Iterable.scala +++ b/src/library/scala/collection/mutable/Iterable.scala @@ -36,7 +36,10 @@ trait Iterable[A] extends Traversable[A] * @version 2.8 */ object Iterable extends TraversableFactory[Iterable] { - implicit def builderFactory[A]: BuilderFactory[A, Iterable[A], Coll] = new VirtualBuilderFactory[A] + implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, Iterable[A]] = + new GenericCanBuildFrom[A] { + def apply() = newBuilder[A] + } def newBuilder[A]: Builder[A, Iterable[A]] = new ArrayBuffer } diff --git a/src/library/scala/collection/mutable/LinearSeq.scala b/src/library/scala/collection/mutable/LinearSeq.scala index 285dc7721d..649d6bdd11 100644 --- a/src/library/scala/collection/mutable/LinearSeq.scala +++ b/src/library/scala/collection/mutable/LinearSeq.scala @@ -27,6 +27,9 @@ trait LinearSeq[A] extends Seq[A] } object LinearSeq extends SeqFactory[LinearSeq] { - implicit def builderFactory[A]: BuilderFactory[A, LinearSeq[A], Coll] = new VirtualBuilderFactory[A] + implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, LinearSeq[A]] = + new GenericCanBuildFrom[A] { + def apply() = newBuilder[A] + } def newBuilder[A]: Builder[A, LinearSeq[A]] = new MutableList[A] } diff --git a/src/library/scala/collection/mutable/LinkedHashMap.scala b/src/library/scala/collection/mutable/LinkedHashMap.scala index 2649a7b376..22e9de381e 100644 --- a/src/library/scala/collection/mutable/LinkedHashMap.scala +++ b/src/library/scala/collection/mutable/LinkedHashMap.scala @@ -23,7 +23,7 @@ import Predef._ * @since 2.7 */ object LinkedHashMap extends MutableMapFactory[LinkedHashMap] { - implicit def builderFactory[A, B]: BuilderFactory[(A, B), LinkedHashMap[A, B], Coll] = new MapBuilderFactory[A, B] + implicit def canBuildFrom[A, B]: CanBuildFrom[Coll, (A, B), LinkedHashMap[A, B]] = new MapCanBuildFrom[A, B] def empty[A, B] = new LinkedHashMap[A, B] } diff --git a/src/library/scala/collection/mutable/LinkedHashSet.scala b/src/library/scala/collection/mutable/LinkedHashSet.scala index af02c455b8..fd606badec 100644 --- a/src/library/scala/collection/mutable/LinkedHashSet.scala +++ b/src/library/scala/collection/mutable/LinkedHashSet.scala @@ -56,7 +56,7 @@ class LinkedHashSet[A] extends Set[A] /** Factory object for `LinkedHashSet` class */ object LinkedHashSet extends SetFactory[LinkedHashSet] { - implicit def builderFactory[A]: BuilderFactory[A, LinkedHashSet[A], Coll] = setBuilderFactory[A] + implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, LinkedHashSet[A]] = setCanBuildFrom[A] override def empty[A]: LinkedHashSet[A] = new LinkedHashSet[A] } diff --git a/src/library/scala/collection/mutable/LinkedList.scala b/src/library/scala/collection/mutable/LinkedList.scala index a881902a67..9d7adb1ebc 100644 --- a/src/library/scala/collection/mutable/LinkedList.scala +++ b/src/library/scala/collection/mutable/LinkedList.scala @@ -32,8 +32,10 @@ class LinkedList[A](_elem: A, _next: LinkedList[A]) extends LinearSeq[A] } object LinkedList extends SeqFactory[LinkedList] { - implicit def builderFactory[A]: BuilderFactory[A, LinkedList[A], Coll] = - new VirtualBuilderFactory[A] + implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, LinkedList[A]] = + new GenericCanBuildFrom[A] { + def apply() = newBuilder[A] + } def newBuilder[A]: Builder[A, LinkedList[A]] = (new MutableList) mapResult ((l: MutableList[A]) => l.toLinkedList) } diff --git a/src/library/scala/collection/mutable/ListBuffer.scala b/src/library/scala/collection/mutable/ListBuffer.scala index 483c516e30..422c23f9ea 100644 --- a/src/library/scala/collection/mutable/ListBuffer.scala +++ b/src/library/scala/collection/mutable/ListBuffer.scala @@ -329,8 +329,10 @@ final class ListBuffer[A] * @version 2.8 */ object ListBuffer extends SeqFactory[ListBuffer] { - implicit def builderFactory[A]: BuilderFactory[A, ListBuffer[A], Coll] = - new VirtualBuilderFactory[A] + implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, ListBuffer[A]] = + new GenericCanBuildFrom[A] { + def apply() = newBuilder[A] + } def newBuilder[A]: Builder[A, ListBuffer[A]] = new AddingBuilder(new ListBuffer[A]) } diff --git a/src/library/scala/collection/mutable/ListMap.scala b/src/library/scala/collection/mutable/ListMap.scala index 329c207a99..a63f3a024c 100644 --- a/src/library/scala/collection/mutable/ListMap.scala +++ b/src/library/scala/collection/mutable/ListMap.scala @@ -46,6 +46,6 @@ class ListMap[A, B] extends Map[A, B] with MapLike[A, B, ListMap[A, B]] { * @version 2.8 */ object ListMap extends MutableMapFactory[ListMap] { - implicit def builderFactory[A, B]: BuilderFactory[(A, B), ListMap[A, B], Coll] = new MapBuilderFactory[A, B] + implicit def canBuildFrom[A, B]: CanBuildFrom[Coll, (A, B), ListMap[A, B]] = new MapCanBuildFrom[A, B] def empty[A, B]: ListMap[A, B] = new ListMap[A, B] } diff --git a/src/library/scala/collection/mutable/Map.scala b/src/library/scala/collection/mutable/Map.scala index 68656e4648..eae9a88bfd 100644 --- a/src/library/scala/collection/mutable/Map.scala +++ b/src/library/scala/collection/mutable/Map.scala @@ -40,7 +40,7 @@ trait Map[A, B] * Currently this returns a HashMap. */ object Map extends MutableMapFactory[Map] { - implicit def builderFactory[A, B]: BuilderFactory[(A, B), Map[A, B], Coll] = new MapBuilderFactory[A, B] + implicit def canBuildFrom[A, B]: CanBuildFrom[Coll, (A, B), Map[A, B]] = new MapCanBuildFrom[A, B] def empty[A, B]: Map[A, B] = new HashMap[A, B] } diff --git a/src/library/scala/collection/mutable/ResizableArray.scala b/src/library/scala/collection/mutable/ResizableArray.scala index 25a41b278e..ec663d4887 100644 --- a/src/library/scala/collection/mutable/ResizableArray.scala +++ b/src/library/scala/collection/mutable/ResizableArray.scala @@ -115,6 +115,9 @@ trait ResizableArray[A] extends Vector[A] } object ResizableArray extends SeqFactory[ResizableArray] { - implicit def builderFactory[A]: BuilderFactory[A, ResizableArray[A], Coll] = new VirtualBuilderFactory[A] + implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, ResizableArray[A]] = + new GenericCanBuildFrom[A] { + def apply() = newBuilder[A] + } def newBuilder[A]: Builder[A, ResizableArray[A]] = new ArrayBuffer[A] } diff --git a/src/library/scala/collection/mutable/Seq.scala b/src/library/scala/collection/mutable/Seq.scala index e6a9acf84a..12786de749 100644 --- a/src/library/scala/collection/mutable/Seq.scala +++ b/src/library/scala/collection/mutable/Seq.scala @@ -36,6 +36,9 @@ trait Seq[A] extends Iterable[A] * @since 2.8 */ object Seq extends SeqFactory[Seq] { - implicit def builderFactory[A]: BuilderFactory[A, Seq[A], Coll] = new VirtualBuilderFactory[A] + implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, Seq[A]] = + new GenericCanBuildFrom[A] { + def apply() = newBuilder[A] + } def newBuilder[A]: Builder[A, Seq[A]] = new ArrayBuffer } diff --git a/src/library/scala/collection/mutable/Set.scala b/src/library/scala/collection/mutable/Set.scala index 81666512c7..09b3046749 100644 --- a/src/library/scala/collection/mutable/Set.scala +++ b/src/library/scala/collection/mutable/Set.scala @@ -38,7 +38,7 @@ trait Set[A] extends Iterable[A] * Currently this returns a HashSet. */ object Set extends SetFactory[Set] { - implicit def builderFactory[A]: BuilderFactory[A, Set[A], Coll] = setBuilderFactory[A] + implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, Set[A]] = setCanBuildFrom[A] override def empty[A]: Set[A] = HashSet.empty[A] } diff --git a/src/library/scala/collection/mutable/Traversable.scala b/src/library/scala/collection/mutable/Traversable.scala index f7889d089e..947d8d3edd 100644 --- a/src/library/scala/collection/mutable/Traversable.scala +++ b/src/library/scala/collection/mutable/Traversable.scala @@ -34,8 +34,10 @@ trait Traversable[A] extends scala.collection.Traversable[A] * @version 2.8 */ object Traversable extends TraversableFactory[Traversable] { - implicit def builderFactory[A]: BuilderFactory[A, Traversable[A], Coll] = - new VirtualBuilderFactory[A] + implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, Traversable[A]] = + new GenericCanBuildFrom[A] { + def apply() = newBuilder[A] + } def newBuilder[A]: Builder[A, Traversable[A]] = new ArrayBuffer } diff --git a/src/library/scala/collection/mutable/Vector.scala b/src/library/scala/collection/mutable/Vector.scala index 42fb62fccd..dd70df3ca5 100644 --- a/src/library/scala/collection/mutable/Vector.scala +++ b/src/library/scala/collection/mutable/Vector.scala @@ -25,6 +25,9 @@ trait Vector[A] extends Seq[A] } object Vector extends SeqFactory[Vector] { - implicit def builderFactory[A]: BuilderFactory[A, Vector[A], Coll] = new VirtualBuilderFactory[A] + implicit def canBuildFrom[A]: CanBuildFrom[Coll, A, Vector[A]] = + new GenericCanBuildFrom[A] { + def apply() = newBuilder[A] + } def newBuilder[A]: Builder[A, Vector[A]] = new ArrayBuffer } diff --git a/src/library/scala/collection/mutable/VectorView.scala b/src/library/scala/collection/mutable/VectorView.scala index 45a21e3429..4a306c54c4 100644 --- a/src/library/scala/collection/mutable/VectorView.scala +++ b/src/library/scala/collection/mutable/VectorView.scala @@ -92,6 +92,6 @@ self => /* * object VectorView { type Coll = TraversableView[_, C] forSome { type C <: scala.collection.Traversable[_] } - implicit def builderFactory[A]: BuilderFactory[A, VectorView[A, Vector[_]], Coll] = new BuilderFactory[A, VectorView[A, mutable.Vector[_]], Coll] { def apply(from: Coll) = new NoBuilder } + implicit def canBuildFrom[A]: CanBuildFrom[Vector[_], A, VectorView[A], Coll] = new CanBuildFrom[mutable.Vector[_], A, VectorView[A], Coll] { : Coll) = new NoBuilder } } */ diff --git a/src/library/scala/collection/mutable/WrappedArray.scala b/src/library/scala/collection/mutable/WrappedArray.scala index f3f5596fd6..4a3d84a303 100644 --- a/src/library/scala/collection/mutable/WrappedArray.scala +++ b/src/library/scala/collection/mutable/WrappedArray.scala @@ -65,10 +65,12 @@ object WrappedArray { case x: Array[Unit] => wrapUnitArray(x).asInstanceOf[WrappedArray[T]] } - implicit def builderFactory[T](implicit m: ClassManifest[T]): BuilderFactory[T, WrappedArray[T], WrappedArray[_]] = - new BuilderFactory[T, WrappedArray[T], WrappedArray[_]] { + implicit def canBuildFrom[T](implicit m: ClassManifest[T]): CanBuildFrom[WrappedArray[_], T, WrappedArray[T]] = + new CanBuildFrom[WrappedArray[_], T, WrappedArray[T]] { def apply(from: WrappedArray[_]): Builder[T, WrappedArray[T]] = ArrayBuilder.make[T]()(m) mapResult WrappedArray.make[T] + def apply: Builder[T, WrappedArray[T]] = + ArrayBuilder.make[T]()(m) mapResult WrappedArray.make[T] } def newBuilder[A]: Builder[A, Vector[A]] = new ArrayBuffer diff --git a/src/library/scala/runtime/RichString.scala b/src/library/scala/runtime/RichString.scala index dd871cf421..66d620f7bc 100644 --- a/src/library/scala/runtime/RichString.scala +++ b/src/library/scala/runtime/RichString.scala @@ -20,8 +20,16 @@ import collection.mutable.{Builder, StringBuilder} object RichString { def newBuilder: Builder[Char, RichString] = new StringBuilder() mapResult (new RichString(_)) - implicit def builderFactory: BuilderFactory[Char, RichString, RichString] = new BuilderFactory[Char, RichString, RichString] { def apply(from: RichString) = newBuilder } - implicit def builderFactory2: BuilderFactory[Char, RichString, String] = new BuilderFactory[Char, RichString, String] { def apply(from: String) = newBuilder } + implicit def canBuildFrom: CanBuildFrom[RichString, Char, RichString] = + new CanBuildFrom[RichString, Char, RichString] { + def apply(from: RichString) = newBuilder + def apply() = newBuilder + } + implicit def canBuildFrom2: CanBuildFrom[String, Char, RichString] = + new CanBuildFrom[String, Char, RichString] { + def apply(from: String) = newBuilder + def apply() = newBuilder + } // just statics for rich string. private final val LF: Char = 0x0A diff --git a/src/library/scala/xml/NodeSeq.scala b/src/library/scala/xml/NodeSeq.scala index bd9999ab3c..0c610bdd90 100644 --- a/src/library/scala/xml/NodeSeq.scala +++ b/src/library/scala/xml/NodeSeq.scala @@ -14,7 +14,7 @@ package scala.xml import collection.immutable import collection.SeqLike import collection.mutable.{Builder, ListBuffer} -import collection.generic.BuilderFactory +import collection.generic.CanBuildFrom /** This object ... * @@ -27,7 +27,11 @@ object NodeSeq { def theSeq = s } type Coll = NodeSeq - implicit def builderFactory: BuilderFactory[Node, NodeSeq, Coll] = new BuilderFactory[Node, NodeSeq, Coll] { def apply(from: Coll) = newBuilder } + implicit def canBuildFrom: CanBuildFrom[Coll, Node, NodeSeq] = + new CanBuildFrom[Coll, Node, NodeSeq] { + def apply(from: Coll) = newBuilder + def apply() = newBuilder + } def newBuilder: Builder[Node, NodeSeq] = new ListBuffer[Node] mapResult fromSeq implicit def seqToNodeSeq(s: Seq[Node]): NodeSeq = fromSeq(s) } |