Skip to content
Browse files

renamed BuilderFactory[El, To, From] -> CanBuil...

renamed BuilderFactory[El, To, From] -> CanBuildFrom[From, El, To] and
added apply() overload to create collections from scratch generically

added def apply() overload to BuilderFactory so that we can also create collections from scratch generically
(see test test/files/pos/collectGenericCC.scala)

renaming:
- BuilderFactory[El, To, From] -> CanBuildFrom[From, El, To]
    bulk type-param reordering using: s/CanBuildFrom\[\s*([^,()\s]*)\s*,(\s+[^\s,()]*)\s*,\s+([^\s,()]*)\s*\]/CanBuildFrom[$3, $1,$2]/
    some argument lists got mixed up because they contained 4 comma's...
- builderFactory -> canBuildFrom

removed explicit implicit value in DocDriver that was
renamed renamed collection/generic/BuilderFactory.scala ->
collection/generic/CanBuildFrom.scala

tested with clean build using ant strap.done -- everything went well on my machine
  • Loading branch information...
1 parent 70bc8f9 commit f818b44b1c7a4ad62271600d85dc41602a7349f7 @adriaanm adriaanm committed Oct 21, 2009
Showing with 304 additions and 167 deletions.
  1. +1 −1 src/compiler/scala/tools/nsc/doc/DefaultDocDriver.scala
  2. +9 −5 src/library/scala/Array.scala
  3. +6 −2 src/library/scala/Enumeration.scala
  4. +4 −3 src/library/scala/LowPriorityImplicits.scala
  5. +8 −5 src/library/scala/Predef.scala
  6. +4 −1 src/library/scala/collection/Iterable.scala
  7. +3 −3 src/library/scala/collection/IterableLike.scala
  8. +3 −3 src/library/scala/collection/IterableProxyLike.scala
  9. +5 −1 src/library/scala/collection/IterableView.scala
  10. +3 −3 src/library/scala/collection/IterableViewLike.scala
  11. +4 −1 src/library/scala/collection/LinearSeq.scala
  12. +1 −1 src/library/scala/collection/Map.scala
  13. +4 −1 src/library/scala/collection/Seq.scala
  14. +6 −6 src/library/scala/collection/SeqLike.scala
  15. +3 −3 src/library/scala/collection/SeqProxyLike.scala
  16. +5 −1 src/library/scala/collection/SeqView.scala
  17. +2 −2 src/library/scala/collection/SeqViewLike.scala
  18. +1 −1 src/library/scala/collection/Set.scala
  19. +1 −1 src/library/scala/collection/SortedMap.scala
  20. +1 −1 src/library/scala/collection/SortedSet.scala
  21. +8 −7 src/library/scala/collection/Traversable.scala
  22. +7 −7 src/library/scala/collection/TraversableLike.scala
  23. +4 −4 src/library/scala/collection/TraversableProxyLike.scala
  24. +5 −1 src/library/scala/collection/TraversableView.scala
  25. +6 −6 src/library/scala/collection/TraversableViewLike.scala
  26. +4 −1 src/library/scala/collection/Vector.scala
  27. +2 −2 src/library/scala/collection/VectorLike.scala
  28. +10 −2 src/library/scala/collection/VectorView.scala
  29. +2 −1 src/library/scala/collection/generic/BitSetFactory.scala
  30. +7 −2 src/library/scala/collection/generic/{BuilderFactory.scala → CanBuildFrom.scala}
  31. +2 −1 src/library/scala/collection/generic/MapFactory.scala
  32. +2 −1 src/library/scala/collection/generic/SetFactory.scala
  33. +2 −1 src/library/scala/collection/generic/SortedMapFactory.scala
  34. +3 −2 src/library/scala/collection/generic/SortedSetFactory.scala
  35. +1 −1 src/library/scala/collection/generic/TraversableFactory.scala
  36. +1 −1 src/library/scala/collection/immutable/BitSet.scala
  37. +1 −1 src/library/scala/collection/immutable/HashMap.scala
  38. +1 −1 src/library/scala/collection/immutable/HashSet.scala
  39. +4 −1 src/library/scala/collection/immutable/Iterable.scala
  40. +4 −1 src/library/scala/collection/immutable/LinearSeq.scala
  41. +7 −3 src/library/scala/collection/immutable/List.scala
  42. +2 −2 src/library/scala/collection/immutable/ListMap.scala
  43. +1 −1 src/library/scala/collection/immutable/ListSet.scala
  44. +1 −1 src/library/scala/collection/immutable/Map.scala
  45. +1 −1 src/library/scala/collection/immutable/MapLike.scala
  46. +5 −1 src/library/scala/collection/immutable/Seq.scala
  47. +1 −1 src/library/scala/collection/immutable/Set.scala
  48. +1 −1 src/library/scala/collection/immutable/SortedMap.scala
  49. +1 −1 src/library/scala/collection/immutable/SortedSet.scala
  50. +15 −12 src/library/scala/collection/immutable/Stream.scala
  51. +4 −2 src/library/scala/collection/immutable/Traversable.scala
  52. +1 −1 src/library/scala/collection/immutable/TreeMap.scala
  53. +12 −8 src/library/scala/collection/immutable/Vector.scala
  54. +3 −3 src/library/scala/collection/interfaces/IterableMethods.scala
  55. +3 −3 src/library/scala/collection/interfaces/SeqMethods.scala
  56. +5 −5 src/library/scala/collection/interfaces/TraversableMethods.scala
  57. +4 −2 src/library/scala/collection/mutable/ArrayBuffer.scala
  58. +1 −1 src/library/scala/collection/mutable/BitSet.scala
  59. +4 −1 src/library/scala/collection/mutable/Buffer.scala
  60. +4 −2 src/library/scala/collection/mutable/DoubleLinkedList.scala
  61. +4 −1 src/library/scala/collection/mutable/GenericArray.scala
  62. +1 −1 src/library/scala/collection/mutable/HashMap.scala
  63. +1 −1 src/library/scala/collection/mutable/HashSet.scala
  64. +4 −1 src/library/scala/collection/mutable/Iterable.scala
  65. +4 −1 src/library/scala/collection/mutable/LinearSeq.scala
  66. +1 −1 src/library/scala/collection/mutable/LinkedHashMap.scala
  67. +1 −1 src/library/scala/collection/mutable/LinkedHashSet.scala
  68. +4 −2 src/library/scala/collection/mutable/LinkedList.scala
  69. +4 −2 src/library/scala/collection/mutable/ListBuffer.scala
  70. +1 −1 src/library/scala/collection/mutable/ListMap.scala
  71. +1 −1 src/library/scala/collection/mutable/Map.scala
  72. +4 −1 src/library/scala/collection/mutable/ResizableArray.scala
  73. +4 −1 src/library/scala/collection/mutable/Seq.scala
  74. +1 −1 src/library/scala/collection/mutable/Set.scala
  75. +4 −2 src/library/scala/collection/mutable/Traversable.scala
  76. +4 −1 src/library/scala/collection/mutable/Vector.scala
  77. +1 −1 src/library/scala/collection/mutable/VectorView.scala
  78. +4 −2 src/library/scala/collection/mutable/WrappedArray.scala
  79. +10 −2 src/library/scala/runtime/RichString.scala
  80. +6 −2 src/library/scala/xml/NodeSeq.scala
  81. +14 −0 test/files/pos/collectGenericCC.scala
View
2 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)
}
}
View
14 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)
View
8 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. */
View
7 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 */
View
13 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
}
View
5 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 */
View
6 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 &gt; 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) {
View
6 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)
View
6 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
+ }
}
View
6 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] {
View
5 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]
}
View
2 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]
}
View
5 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")
View
12 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
View
6 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)
View
6 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
+ }
}
View
4 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"
View
2 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]
}
View
2 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)
}
View
2 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)
}
View
15 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]
}
View
14 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)
View
8 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)
View
6 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
+ }
}
View
12 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]
View
5 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]
View
4 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)
View
12 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
+ }
}
View
3 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
}
}
View
9 ...a/collection/generic/BuilderFactory.scala → ...ala/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]
}
View
3 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
}
}
View
3 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]
}
}
View
3 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]
}
}
View
5 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)
}
}
View
2 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]
}
View
2 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 = {
View
2 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
}
View
2 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
}
View
5 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
}
View
5 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
}
View
10 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
View
4 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
}
View
2 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]
}
View
2 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]
View
2 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
View
6 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
}
View
2 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
View
2 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]
}
View
2 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]
}
View
27 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]] {
View
6 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
}
View
2 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)
}
View
20 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]
}
View
6 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]
View
6 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]
View
10 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
View
6 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]
}
View
2 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
}
View
5 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
}
View
6 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] = _
View
5 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)
View
2 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]
}
View
2 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]
}
View
5 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
}
View
5 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]
}
View
2 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]
}
View
2 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]
}
View
6 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)
}
View
6 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])
}
View
2 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]
}
View
2 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]
}
View
5 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]
}
View
5 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
}
View
2 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]
}
View
6 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
}
View
5 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
}
View
2 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 }
}
*/
View
6 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]] =