summaryrefslogtreecommitdiff
path: root/src/library/scalax/collection/SizedIterable.scala
diff options
context:
space:
mode:
authorAntonio Cunei <antonio.cunei@epfl.ch>2008-11-25 18:05:48 +0000
committerAntonio Cunei <antonio.cunei@epfl.ch>2008-11-25 18:05:48 +0000
commitaf47e5b433ea538bf096a176c88f3c91116e09cd (patch)
treeb3e66e93fb653570ebbef16183cf4f2be2111c12 /src/library/scalax/collection/SizedIterable.scala
parent2d61f09332dbc6038f869c6a23a95dca1bc3b6c7 (diff)
downloadscala-af47e5b433ea538bf096a176c88f3c91116e09cd.tar.gz
scala-af47e5b433ea538bf096a176c88f3c91116e09cd.tar.bz2
scala-af47e5b433ea538bf096a176c88f3c91116e09cd.zip
Merging everything from the 2.8.x development b...
Merging everything from the 2.8.x development branch back to trunk. - If you were working on trunk, please keep working on trunk If you were - working on 2.8-devel, please switch to trunk now
Diffstat (limited to 'src/library/scalax/collection/SizedIterable.scala')
-rw-r--r--src/library/scalax/collection/SizedIterable.scala38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/library/scalax/collection/SizedIterable.scala b/src/library/scalax/collection/SizedIterable.scala
new file mode 100644
index 0000000000..f4e13f3521
--- /dev/null
+++ b/src/library/scalax/collection/SizedIterable.scala
@@ -0,0 +1,38 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2002-2007, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+// $Id: Collection.scala 12340 2007-07-17 15:29:47Z mcdirmid $
+
+
+package scalax.collection
+
+/** Variant of <code>Iterable</code> which also demands
+ * implementation of a `size` method.
+ * Basically, this trait just adds size to Iterable,
+ * and provides an optimized implementation of toArray based on it.
+ *
+ * @author Martin Odersky
+ * @version 2.8
+ */
+trait SizedIterable[+A] extends Iterable[A] {
+
+ /** Returns the number of elements in this collection.
+ *
+ * @return number of collection elements.
+ */
+ def size : Int
+
+ /** Converts this iterable to a fresh Array with <code>size</code> elements.
+ */
+ override def toArray[B >: A]: Array[B] = {
+ val result = new Array[B](size)
+ copyToArray(result, 0)
+ result
+ }
+}
+