summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2007-01-25 13:50:44 +0000
committerMartin Odersky <odersky@gmail.com>2007-01-25 13:50:44 +0000
commitd169735abb70d59995e3e8783cea62f876654ad4 (patch)
tree8c4f19866306d4d6b8ac0b552e61c5aa5fe1c567
parentdd50828fda67a1af2b4bdaf760d88d065fb9a45f (diff)
downloadscala-d169735abb70d59995e3e8783cea62f876654ad4.tar.gz
scala-d169735abb70d59995e3e8783cea62f876654ad4.tar.bz2
scala-d169735abb70d59995e3e8783cea62f876654ad4.zip
fixed bugs 900,892, contrib 296.
-rw-r--r--src/library/scala/Array.scala19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/library/scala/Array.scala b/src/library/scala/Array.scala
index dd253ab658..b8b6d1fe4c 100644
--- a/src/library/scala/Array.scala
+++ b/src/library/scala/Array.scala
@@ -157,14 +157,29 @@ object Array {
array
}
- /** This method is called in a pattern match { case Array(...) => }.
+ /** Create an array containing several copies of an element.
+ *
+ * @param n the length of the resulting array
+ * @param elem the element composing the resulting array
+ * @return an array composed of n elements all equal to elem
+ */
+ def make[a](n: Int, elem: a): List[a] = {
+ val a = new Array[a]
+ var i = 0
+ while (i < n) {
+ a(i) = elem
+ i = i + 1
+ }
+ a
+ }
+
+ /** This method is called in a pattern match { case Array(...) => }.
*
* @param x the selector value
* @return array wrapped in an option, if this is a Seq, otherwise none
*/
def unapplySeq[A](x: Any): Option[Seq[A]] =
if (x.isInstanceOf[Array[A]]) Some(x.asInstanceOf[Array[A]]) else None
-
}
/** This class represents polymorphic arrays. It is never instantiated.