diff options
7 files changed, 48 insertions, 71 deletions
diff --git a/src/library/scala/collection/SeqLike.scala b/src/library/scala/collection/SeqLike.scala index 8770de9c36..06e8b363c8 100644 --- a/src/library/scala/collection/SeqLike.scala +++ b/src/library/scala/collection/SeqLike.scala @@ -289,6 +289,7 @@ trait SeqLike[+A, +Repr] extends IterableLike[A, Repr] { self => /** Returns index of the first element satisfying a predicate, or `-1`. */ + @deprecated("Use indexWhere(p) instead.") def findIndexOf(p: A => Boolean): Int = indexWhere(p) /** Finds index of first occurrence of some value in this $coll. diff --git a/src/library/scala/collection/interfaces/IterableMethods.scala b/src/library/scala/collection/interfaces/IterableMethods.scala index 6c22a298c3..0f6bc0a694 100644 --- a/src/library/scala/collection/interfaces/IterableMethods.scala +++ b/src/library/scala/collection/interfaces/IterableMethods.scala @@ -17,14 +17,18 @@ import annotation.unchecked.uncheckedVariance /** * @since 2.8 */ -trait IterableMethods[+A, +This <: IterableLike[A, This] with Iterable[A]] extends TraversableMethods[A, This] -{ +trait IterableMethods[+A, +This <: IterableLike[A, This] with Iterable[A]] extends TraversableMethods[A, This] { + self: Iterable[A] => + // abstract def iterator: Iterator[A] // concrete def dropRight(n: Int): Iterable[A] + def grouped(size: Int): Iterator[Iterable[A]] def sameElements[B >: A](that: Iterable[B]): Boolean + def sliding[B >: A](size: Int): Iterator[Iterable[A]] + def sliding[B >: A](size: Int, step: Int): Iterator[Iterable[A]] 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: CanBuildFrom[This, (A1, B), That]): That diff --git a/src/library/scala/collection/interfaces/MapMethods.scala b/src/library/scala/collection/interfaces/MapMethods.scala index fd6e7ad2a7..5852db47a7 100644 --- a/src/library/scala/collection/interfaces/MapMethods.scala +++ b/src/library/scala/collection/interfaces/MapMethods.scala @@ -15,9 +15,10 @@ import generic._ * @since 2.8 */ trait MapMethods[A, +B, +This <: MapLike[A, B, This] with Map[A, B]] -extends IterableMethods[(A, B), This] -with SubtractableMethods[A, This] -{ + extends IterableMethods[(A, B), This] + with SubtractableMethods[A, This] { + self: Map[A, B] => + // abstract def empty: This def get(key: A): Option[B] diff --git a/src/library/scala/collection/interfaces/SeqMethods.scala b/src/library/scala/collection/interfaces/SeqMethods.scala index 401c5e6c55..1c1af74eca 100644 --- a/src/library/scala/collection/interfaces/SeqMethods.scala +++ b/src/library/scala/collection/interfaces/SeqMethods.scala @@ -16,14 +16,21 @@ import scala.reflect.ClassManifest /** * @since 2.8 */ -trait SeqMethods[+A, +This <: SeqLike[A, This] with Seq[A]] extends IterableMethods[A, This] -{ +trait SeqMethods[+A, +This <: SeqLike[A, This] with Seq[A]] extends IterableMethods[A, This] { + self: Seq[A] => + // abstract def apply(idx: Int): A def length: Int + // concrete + def +:[B >: A, That](elem: B)(implicit bf: CanBuildFrom[This, B, That]): That + def :+[B >: A, That](elem: B)(implicit bf: CanBuildFrom[This, B, That]): That def contains(elem: Any): Boolean + def containsSlice[B](that: Seq[B]): Boolean + def corresponds[B](that: Seq[B])(p: (A,B) => Boolean): Boolean def diff[B >: A, That](that: Seq[B]): This + def distinct: This def endsWith[B](that: Seq[B]): Boolean def indexOfSlice[B >: A](that: Seq[B]): Int def indexOfSlice[B >: A](that: Seq[B], fromIndex: Int): Int @@ -44,13 +51,17 @@ trait SeqMethods[+A, +This <: SeqLike[A, This] with Seq[A]] extends IterableMeth 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 distinct: This def reverse: This def reverseIterator: Iterator[A] + def reverseMap[B, That](f: A => B)(implicit bf: CanBuildFrom[This, B, That]): That def segmentLength(p: A => Boolean, from: Int): Int + def sortBy[B](f: A => B)(implicit ord: Ordering[B]): This + def sortWith(lt: (A, A) => Boolean): This + def sorted[B >: A](implicit ord: Ordering[B]): This 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: CanBuildFrom[This, B, That]): That + def updated[B >: A, That](index: Int, elem: 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/SetMethods.scala b/src/library/scala/collection/interfaces/SetMethods.scala index 453143b790..3b24436498 100644 --- a/src/library/scala/collection/interfaces/SetMethods.scala +++ b/src/library/scala/collection/interfaces/SetMethods.scala @@ -18,17 +18,15 @@ import annotation.unchecked.uncheckedVariance * @since 2.8 */ trait AddableMethods[A, +This <: Addable[A, This]] { - protected def repr: This def +(elem: A): This - def + (elem1: A, elem2: A, elems: A*): This - def ++ (xs: TraversableOnce[A]): This + def +(elem1: A, elem2: A, elems: A*): This + def ++(xs: TraversableOnce[A]): This } /** * @since 2.8 */ trait SubtractableMethods[A, +This <: Subtractable[A, This]] { - protected def repr: This def -(elem: A): This def -(elem1: A, elem2: A, elems: A*): This def --(xs: TraversableOnce[A]): This @@ -38,10 +36,11 @@ trait SubtractableMethods[A, +This <: Subtractable[A, This]] { * @since 2.8 */ trait SetMethods[A, +This <: SetLike[A, This] with Set[A]] -extends IterableMethods[A, This] -with AddableMethods[A, This] -with SubtractableMethods[A, This] -{ + extends IterableMethods[A, This] + with AddableMethods[A, This] + with SubtractableMethods[A, This] { + self: Set[A] => + // abstract def empty: This def contains(elem: A): Boolean diff --git a/src/library/scala/collection/interfaces/TraversableMethods.scala b/src/library/scala/collection/interfaces/TraversableMethods.scala index d381b1dc24..9c1ff319ab 100644 --- a/src/library/scala/collection/interfaces/TraversableMethods.scala +++ b/src/library/scala/collection/interfaces/TraversableMethods.scala @@ -16,61 +16,20 @@ import scala.reflect.ClassManifest /** * @since 2.8 */ -trait TraversableMethods[+A, +This <: TraversableLike[A, This] with Traversable[A]] -{ - // abstract - def foreach[U](f: A => U): Unit +trait TraversableMethods[+A, +This <: TraversableLike[A, This]] extends TraversableOnceMethods[A] { + self: Traversable[A] => // maps/iteration 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 collect[B, That](pf: PartialFunction[A, B])(implicit bf: CanBuildFrom[This, B, That]): That - def scanLeft[B, That](z: B)(op: (B, A) => B)(implicit bf: CanBuildFrom[This, B, That]): That // could be fold or new collection too - where to put it? + def scanLeft[B, That](z: B)(op: (B, A) => B)(implicit bf: CanBuildFrom[This, B, That]): That def scanRight[B, That](z: B)(op: (A, B) => B)(implicit bf: CanBuildFrom[This, B, That]): That // new collections def ++[B >: A, That](xs: TraversableOnce[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 - - // conversions - def toArray[B >: A : ClassManifest]: Array[B] - def toIterable: Iterable[A] - def toList: List[A] - def toSeq: Seq[A] - def toSet[B >: A]: immutable.Set[B] - def toStream: Stream[A] - def toIndexedSeq[B >: A]: immutable.IndexedSeq[B] - def toBuffer[B >: A]: mutable.Buffer[B] - - // strings - def addString(b: StringBuilder): StringBuilder - def addString(b: StringBuilder, sep: String): StringBuilder - def addString(b: StringBuilder, start: String, sep: String, end: String): StringBuilder - def mkString(sep: String): String - def mkString(start: String, sep: String, end: String): String - def mkString: String - - // folds - def /: [B](z: B)(op: (B, A) => B): B - def :\ [B](z: B)(op: (A, B) => B): B - def foldLeft[B](z: B)(op: (B, A) => B): B - def foldRight[B](z: B)(op: (A, B) => B): B - def reduceLeftOption[B >: A](op: (B, A) => B): Option[B] - def reduceLeft[B >: A](op: (B, A) => B): B - def reduceRightOption[B >: A](op: (A, B) => B): Option[B] - def reduceRight[B >: A](op: (A, B) => B): B - - // conditions - def exists(p: A => Boolean): Boolean - def forall(p: A => Boolean): Boolean - def hasDefiniteSize: Boolean - def isEmpty: Boolean - def nonEmpty: Boolean // element retrieval - def find(p: A => Boolean): Option[A] def head: A def headOption: Option[A] def last: A @@ -81,6 +40,7 @@ trait TraversableMethods[+A, +This <: TraversableLike[A, This] with Traversable[ def dropWhile(p: A => Boolean): Traversable[A] def filter(p: A => Boolean): Traversable[A] def filterNot(p: A => Boolean): Traversable[A] + def withFilter(p: A => Boolean): FilterMonadic[A, Traversable[A]] def init: Traversable[A] def slice(from: Int, until: Int): Traversable[A] def tail: Traversable[A] @@ -101,9 +61,4 @@ trait TraversableMethods[+A, +This <: TraversableLike[A, This] with Traversable[ // views def view: TraversableView[A, This] def view(from: Int, until: Int): TraversableView[A, This] - - // def sum[B >: A](implicit num: Numeric[B]): B - // def product[B >: A](implicit num: Numeric[B]): B - // def min[B >: A](implicit cmp: Ordering[B]): A - // def max[B >: A](implicit cmp: Ordering[B]): A } diff --git a/src/library/scala/collection/interfaces/TraversableOnceMethods.scala b/src/library/scala/collection/interfaces/TraversableOnceMethods.scala index 1e71215efd..8a250795a9 100644 --- a/src/library/scala/collection/interfaces/TraversableOnceMethods.scala +++ b/src/library/scala/collection/interfaces/TraversableOnceMethods.scala @@ -39,26 +39,32 @@ trait TraversableOnceMethods[+A] { def reduceLeftOption[B >: A](op: (B, A) => B): Option[B] def reduceRightOption[B >: A](op: (A, B) => B): Option[B] - def sum[B >: A](implicit num: Numeric[B]): B - def product[B >: A](implicit num: Numeric[B]): B - def min[B >: A](implicit cmp: Ordering[B]): A - def max[B >: A](implicit cmp: Ordering[B]): A - - // copies and conversions + // copies def copyToBuffer[B >: A](dest: Buffer[B]): Unit def copyToArray[B >: A](xs: Array[B], start: Int, len: Int): Unit def copyToArray[B >: A](xs: Array[B], start: Int): Unit def copyToArray[B >: A](xs: Array[B]): Unit + // conversions def toArray[B >: A : ClassManifest]: Array[B] + def toBuffer[B >: A]: mutable.Buffer[B] + def toIndexedSeq[B >: A]: immutable.IndexedSeq[B] def toIterable: Iterable[A] def toIterator: Iterator[A] def toList: List[A] def toMap[T, U](implicit ev: A <:< (T, U)): immutable.Map[T, U] + def toSeq: Seq[A] def toSet[B >: A]: immutable.Set[B] def toStream: Stream[A] def toTraversable: Traversable[A] + // type-constrained folds + def sum[B >: A](implicit num: Numeric[B]): B + def product[B >: A](implicit num: Numeric[B]): B + def min[B >: A](implicit cmp: Ordering[B]): A + def max[B >: A](implicit cmp: Ordering[B]): A + + // strings def mkString(start: String, sep: String, end: String): String def mkString(sep: String): String def mkString: String |