diff options
author | michelou <michelou@epfl.ch> | 2004-05-13 09:24:42 +0000 |
---|---|---|
committer | michelou <michelou@epfl.ch> | 2004-05-13 09:24:42 +0000 |
commit | bb2e5cbb9cb285bd3ecd9b387126de2659224190 (patch) | |
tree | 99a6dc72165bde3fd7aef0b47a55822731408131 | |
parent | 1e724a3d4618791ae027b7a70c7f2f3b5f5c5b75 (diff) | |
download | scala-bb2e5cbb9cb285bd3ecd9b387126de2659224190.tar.gz scala-bb2e5cbb9cb285bd3ecd9b387126de2659224190.tar.bz2 scala-bb2e5cbb9cb285bd3ecd9b387126de2659224190.zip |
- added overloaded methods 'range' with step va...
- added overloaded methods 'range' with step value/function.
-rw-r--r-- | sources/scala/List.scala | 27 | ||||
-rw-r--r-- | test/files/dis/List.check | 2 |
2 files changed, 27 insertions, 2 deletions
diff --git a/sources/scala/List.scala b/sources/scala/List.scala index 0ba4b74102..fec4ac4ed6 100644 --- a/sources/scala/List.scala +++ b/sources/scala/List.scala @@ -1,6 +1,6 @@ /* __ *\ ** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2003-04, LAMP/EPFL ** +** / __/ __// _ | / / / _ | (c) 2003-2004, LAMP/EPFL ** ** __\ \/ /__/ __ |/ /__/ __ | ** ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** @@ -29,11 +29,34 @@ object List { /** Create a sorted list of all integers in a range. * + * @param from the start value of the list + * @param end the end value of the list * @return the sorted list of all integers in range [from;end). */ def range(from: Int, end: Int): List[Int] = + range(from, end, 1); + + /** Create a sorted list of all integers in a range. + * + * @param from the start value of the list + * @param end the end value of the list + * @param step the increment value of the list + * @return the sorted list of all integers in range [from;end). + */ + def range(from: Int, end: Int, step: Int): List[Int] = + if (from >= end) Nil + else from :: range(from + step, end, step); + + /** Create a sorted list of all integers in a range. + * + * @param from the start value of the list + * @param end the end value of the list + * @param step the increment function of the list + * @return the sorted list of all integers in range [from;end). + */ + def range(from: Int, end: Int, step: Int => Int): List[Int] = if (from >= end) Nil - else from :: range(from + 1, end); + else from :: range(step(from), end, step); /** Create a list containing several copies of an element. * diff --git a/test/files/dis/List.check b/test/files/dis/List.check index 194a9f7c0a..05f54229a2 100644 --- a/test/files/dis/List.check +++ b/test/files/dis/List.check @@ -57,6 +57,8 @@ object List extends java.lang.Object with scala.ScalaObject { final def flatten[a](scala.List[scala.List[a]]): scala.List[a]; final def tabulate[a](scala.Int, scala.Function1[scala.Int, a]): scala.List[a]; final def make[a](scala.Int, a): scala.List[a]; + final def range(scala.Int, scala.Int, scala.Function1[scala.Int, scala.Int]): scala.List[scala.Int]; + final def range(scala.Int, scala.Int, scala.Int): scala.List[scala.Int]; final def range(scala.Int, scala.Int): scala.List[scala.Int]; final def apply[A](A*): scala.List[A] } |