summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpradel <pradel@epfl.ch>2008-05-02 06:04:27 +0000
committerpradel <pradel@epfl.ch>2008-05-02 06:04:27 +0000
commit5241150491f1543796c80cf7dd594ce27a517697 (patch)
treed5d3f6fcfa31b4d11cc97d9655cc701cd295b251
parent78ab4f9e7a46c913ce3f46204a7eea430ad24131 (diff)
downloadscala-5241150491f1543796c80cf7dd594ce27a517697.tar.gz
scala-5241150491f1543796c80cf7dd594ce27a517697.tar.bz2
scala-5241150491f1543796c80cf7dd594ce27a517697.zip
fixed #790
-rw-r--r--src/library/scala/RandomAccessSeq.scala20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/library/scala/RandomAccessSeq.scala b/src/library/scala/RandomAccessSeq.scala
index 66faeb10e1..437d7ae8fb 100644
--- a/src/library/scala/RandomAccessSeq.scala
+++ b/src/library/scala/RandomAccessSeq.scala
@@ -10,6 +10,8 @@
package scala
+import collection.mutable.ArrayBuffer
+
object RandomAccessSeq {
trait Projection[+A] extends Seq.Projection[A] with RandomAccessSeq[A] {
override def projection = this
@@ -161,6 +163,24 @@ trait RandomAccessSeq[+A] extends Seq[A] {
override def reverse : RandomAccessSeq.Projection[A] = RandomAccessSeq.this.projection
}
+ /** Partitions this random access sequence in two random access
+ * sequences according to a predicate.
+ *
+ * @param p the predicate on which to partition
+ * @return a pair of random access sequences: the sequence of all elements
+ * that satisfy the predicate <code>p</code> and the sequence of
+ * all elements that do not.
+ * The relative order of the elements in the resulting sequences
+ * is the same as in the original sequence.
+ */
+ override def partition(p: A => Boolean): (RandomAccessSeq[A], RandomAccessSeq[A]) = {
+ val matched = new ArrayBuffer[A]
+ val failed = new ArrayBuffer[A]
+ val elems = elements
+ while (elems.hasNext) { val x = elems.next; if (p(x)) matched += x else failed += x }
+ (matched, failed)
+ }
+
/** insert segment <code>patch</code> into this sequence at <code>from</code>
* replacing <code>replaced</code> elements. The result is a projection.
*/