diff options
author | michelou <michelou@epfl.ch> | 2005-09-21 13:13:59 +0000 |
---|---|---|
committer | michelou <michelou@epfl.ch> | 2005-09-21 13:13:59 +0000 |
commit | 8ef0c9bfc783606b79cd2ce35d35ec1fe73b60b7 (patch) | |
tree | ec8786f7a50c91d839c13c3ce0f86ae53af41942 /sources/examples/iterators.scala | |
parent | 3761cb4b3a1c03f5daa2fac28d19f6f398072ffe (diff) | |
download | scala-8ef0c9bfc783606b79cd2ce35d35ec1fe73b60b7.tar.gz scala-8ef0c9bfc783606b79cd2ce35d35ec1fe73b60b7.tar.bz2 scala-8ef0c9bfc783606b79cd2ce35d35ec1fe73b60b7.zip |
- removed instantiation of polymorphic arrays w...
- removed instantiation of polymorphic arrays with primitive types.
Diffstat (limited to 'sources/examples/iterators.scala')
-rw-r--r-- | sources/examples/iterators.scala | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/sources/examples/iterators.scala b/sources/examples/iterators.scala index 75ef1ed619..5f951156cf 100644 --- a/sources/examples/iterators.scala +++ b/sources/examples/iterators.scala @@ -2,17 +2,24 @@ package examples; object iterators { + def Array(elems: Double*): Array[Double] = { + val ar = new Array[Double](elems.length); + for (val i <- Iterator.range(0, elems.length)) + ar(i) = elems(i); + ar + } + def printArray(xs: Array[Double]) = Iterator.fromArray(xs) foreach { x => Console.println(x) }; def findGreater(xs: Array[Double], limit: Double) = Iterator.fromArray(xs) .zip(Iterator.from(0)) - .filter{case Pair(x, i) => x > limit} + .filter{case Pair(x, i) => x > limit } .map{case Pair(x, i) => i} def main(args: Array[String]) = { - val ar = Array[Double](6, 2, 8, 5, 1); + val ar = Array/*[Double]*/(6, 2, 8, 5, 1); printArray(ar); Console.println("Elements greater than 3.0:"); findGreater(ar, 3.0) foreach { x => Console.println(ar(x)) } |