diff options
Diffstat (limited to 'src')
7 files changed, 191 insertions, 8 deletions
diff --git a/src/library/scala/collection/Iterator.scala b/src/library/scala/collection/Iterator.scala index beaeacf499..0ae5eda848 100644 --- a/src/library/scala/collection/Iterator.scala +++ b/src/library/scala/collection/Iterator.scala @@ -675,7 +675,7 @@ trait Iterator[+A] { self => * @param op The operator to apply * @return If the iterable is non-empty, the result of the operations as an Option, otherwise None. */ - def reduceLeftOpt[B >: A](op: (B, A) => B): Option[B] = { + def reduceLeftOption[B >: A](op: (B, A) => B): Option[B] = { if (!hasNext) None else Some(reduceLeft(op)) } @@ -684,7 +684,7 @@ trait Iterator[+A] { self => * @param op The operator to apply * @return If the iterable is non-empty, the result of the operations as an Option, otherwise None. */ - def reduceRightOpt[B >: A](op: (A, B) => B): Option[B] = { + def reduceRightOption[B >: A](op: (A, B) => B): Option[B] = { if (!hasNext) None else Some(reduceRight(op)) } diff --git a/src/library/scala/collection/Traversable.scala b/src/library/scala/collection/Traversable.scala index d527836603..6ed1844915 100644 --- a/src/library/scala/collection/Traversable.scala +++ b/src/library/scala/collection/Traversable.scala @@ -55,9 +55,9 @@ trait Traversable[+A] extends TraversableTemplate[A, Traversable[A]] override def foldRight[B](z: B)(op: (A, B) => B): B override def :\ [B](z: B)(op: (A, B) => B): B override def reduceLeft[B >: A](op: (B, A) => B): B - override def reduceLeftOpt[B >: A](op: (B, A) => B): Option[B] + override def reduceLeftOption[B >: A](op: (B, A) => B): Option[B] override def reduceRight[B >: A](op: (A, B) => B): B - override def reduceRightOpt[B >: A](op: (A, B) => B): Option[B] + override def reduceRightOption[B >: A](op: (A, B) => B): Option[B] override def head: A override def headOption: Option[A] override def tail: Traversable[A] diff --git a/src/library/scala/collection/generic/TraversableFactory.scala b/src/library/scala/collection/generic/TraversableFactory.scala index 1b20fb40a8..08633f5e3b 100644 --- a/src/library/scala/collection/generic/TraversableFactory.scala +++ b/src/library/scala/collection/generic/TraversableFactory.scala @@ -8,12 +8,9 @@ // $Id$ - package scala.collection.generic import scala.collection._ -import scala.collection._ - /** A template for companion objects of Traversable and subclasses thereof. */ abstract class TraversableFactory[CC[X] <: Traversable[X] with TraversableClass[X, CC]] diff --git a/src/library/scala/collection/generic/TraversableProxyTemplate.scala b/src/library/scala/collection/generic/TraversableProxyTemplate.scala index ae711b9260..4c6fa5403a 100644 --- a/src/library/scala/collection/generic/TraversableProxyTemplate.scala +++ b/src/library/scala/collection/generic/TraversableProxyTemplate.scala @@ -74,7 +74,6 @@ trait TraversableProxyTemplate[+A, +This <: TraversableTemplate[A, This] with Tr override def toSequence: Sequence[A] = self.toSequence override def toStream: Stream[A] = self.toStream override def toSet[B >: A]: immutable.Set[B] = self.toSet -// override def sortWith(lt : (A,A) => Boolean): This = self.sortWith(lt) override def mkString(start: String, sep: String, end: String): String = self.mkString(start, sep, end) override def mkString(sep: String): String = self.mkString(sep) override def mkString: String = self.mkString @@ -85,3 +84,12 @@ trait TraversableProxyTemplate[+A, +This <: TraversableTemplate[A, This] with Tr override def view = self.view override def view(from: Int, until: Int): TraversableView[A, This] = self.view(from, until) } + +private class TraversableProxyTemplateConfirmation[+A, +This <: TraversableTemplate[A, This] with Traversable[A]] + extends TraversableProxyTemplate[A, Traversable[A]] + with interfaces.TraversableMethods[A, Traversable[A]] +{ + def self: This = thisCollection.asInstanceOf[This] + protected[this] def newBuilder = collection.Traversable.newBuilder[A] + // : Builder[A, This] +} diff --git a/src/library/scala/collection/interfaces/IterableMethods.scala b/src/library/scala/collection/interfaces/IterableMethods.scala new file mode 100644 index 0000000000..db8f742f83 --- /dev/null +++ b/src/library/scala/collection/interfaces/IterableMethods.scala @@ -0,0 +1,25 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +package scala.collection.interfaces + +import scala.collection._ +import generic._ +import mutable.Buffer +import scala.reflect.ClassManifest + +trait IterableMethods[+A, +This <: IterableTemplate[A, This] with Iterable[A]] extends TraversableMethods[A, This] +{ + def dropRight(n: Int): Iterable[A] + def iterator: Iterator[A] + def sameElements[B >: A](that: Iterable[B]): Boolean + def takeRight(n: Int): Iterable[A] + + override def view: IterableView[A, This] + override def view(from: Int, until: Int): IterableView[A, This] +}
\ No newline at end of file diff --git a/src/library/scala/collection/interfaces/SequenceMethods.scala b/src/library/scala/collection/interfaces/SequenceMethods.scala new file mode 100644 index 0000000000..130d8a6e91 --- /dev/null +++ b/src/library/scala/collection/interfaces/SequenceMethods.scala @@ -0,0 +1,53 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +package scala.collection.interfaces + +import scala.collection._ +import generic._ +import mutable.Buffer +import scala.reflect.ClassManifest + +trait SequenceMethods[+A, +This <: SequenceTemplate[A, This] with Sequence[A]] extends IterableMethods[A, This] +{ + def apply(idx: Int): A + def contains(elem: Any): Boolean + def diff[B >: A, That](that: Sequence[B]): This + def endsWith[B](that: Sequence[B]): Boolean + def indexOfSeq[B >: A](that: Sequence[B]): Int + def indexOfSeq[B >: A](that: Sequence[B], fromIndex: Int): Int + def indexOf[B >: A](elem: B): Int + def indexOf[B >: A](elem: B, from: Int): Int + def indexWhere(p: A => Boolean): Int + def indexWhere(p: A => Boolean, from: Int): Int + def indices: Range + def intersect[B >: A, That](that: Sequence[B]): This + def isDefinedAt(x: Int): Boolean + def lastIndexOfSeq[B >: A](that: Sequence[B]): Int + def lastIndexOfSeq[B >: A](that: Sequence[B], fromIndex: Int): Int + def lastIndexOf[B >: A](elem: B): Int + def lastIndexOf[B >: A](elem: B, end: Int): Int + def lastIndexWhere(p: A => Boolean): Int + def lastIndexWhere(p: A => Boolean, end: Int): Int + def length: 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: Sequence[B], replaced: Int)(implicit bf: BuilderFactory[B, That, This]): That + def prefixLength(p: A => Boolean): Int + def removeDuplicates: This + def reverse: This + def reverseIterator: Iterator[A] + def segmentLength(p: A => Boolean, from: Int): Int + def slice(from: Int): Sequence[A] + def startsWith[B](that: Sequence[B]): Boolean + def startsWith[B](that: Sequence[B], offset: Int): Boolean + def union[B >: A, That](that: Sequence[B])(implicit bf: BuilderFactory[B, That, This]): That + + override def view: SequenceView[A, This] + override def view(from: Int, until: Int): SequenceView[A, This] +}
\ No newline at end of file diff --git a/src/library/scala/collection/interfaces/TraversableMethods.scala b/src/library/scala/collection/interfaces/TraversableMethods.scala new file mode 100644 index 0000000000..b0df866c9c --- /dev/null +++ b/src/library/scala/collection/interfaces/TraversableMethods.scala @@ -0,0 +1,100 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +package scala.collection.interfaces + +import scala.collection._ +import generic._ +import mutable.Buffer +import scala.reflect.ClassManifest + +trait TraversableMethods[+A, +This <: TraversableTemplate[A, This] with Traversable[A]] +{ + // 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 foreach[U](f: A => U): Unit + + // 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 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 toSequence: Sequence[A] + def toStream: Stream[A] + + // 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 + def lastOption: Option[A] + + // subcollections + def drop(n: Int): Traversable[A] + def dropWhile(p: A => Boolean): Traversable[A] + def filter(p: A => Boolean): Traversable[A] + def filterNot(p: A => Boolean): Traversable[A] + def init: Traversable[A] + def slice(from: Int, until: Int): Traversable[A] + def tail: Traversable[A] + def take(n: Int): Traversable[A] + def takeWhile(p: A => Boolean): Traversable[A] + + // subdivisions + def groupBy[K](f: A => K): Map[K, Traversable[A]] + def partition(p: A => Boolean): (Traversable[A], Traversable[A]) + def span(p: A => Boolean): (Traversable[A], Traversable[A]) + def splitAt(n: Int): (Traversable[A], Traversable[A]) + + // info + def count(p: A => Boolean): Int + def size: Int + def stringPrefix: String + + // 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 +} |