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 /sources | |
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.
Diffstat (limited to 'sources')
-rw-r--r-- | sources/scala/List.scala | 27 |
1 files changed, 25 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. * |