diff options
author | NAME <USER@epfl.ch> | 2008-02-05 17:28:14 +0000 |
---|---|---|
committer | NAME <USER@epfl.ch> | 2008-02-05 17:28:14 +0000 |
commit | 864c5a385a8a75c84d8ef7e444d0de3478133cc9 (patch) | |
tree | 68ec93e2bee0d592185c84f54b3bd48b85b03459 /src/library | |
parent | b7470d8225d631ac59aa827c6b249626f1c21b1d (diff) | |
download | scala-864c5a385a8a75c84d8ef7e444d0de3478133cc9.tar.gz scala-864c5a385a8a75c84d8ef7e444d0de3478133cc9.tar.bz2 scala-864c5a385a8a75c84d8ef7e444d0de3478133cc9.zip |
Fixed #327, #332
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/Iterator.scala | 6 | ||||
-rw-r--r-- | src/library/scala/Range.scala | 14 | ||||
-rw-r--r-- | src/library/scala/runtime/RichInt.scala | 6 |
3 files changed, 11 insertions, 15 deletions
diff --git a/src/library/scala/Iterator.scala b/src/library/scala/Iterator.scala index 3701623f4b..fbfd4c3e5c 100644 --- a/src/library/scala/Iterator.scala +++ b/src/library/scala/Iterator.scala @@ -108,13 +108,13 @@ object Iterator { * <code>e<sub>n+1</sub> = e<sub>n</sub> + 1</code> * where <code>e<sub>0</sub> = start</code> * and <code>e<sub>i</sub> < end</code>. However, - * if start > end, then it will return an empty trange. + * if <code>start ≥ end</code>, then it will return an empty range. * * @param start the start value of the iterator * @param end the end value of the iterator * @return the iterator with values in range <code>[start;end)</code>. */ - def range(start: Int, end: Int): Range = range(start, end, 1) + def range(start: Int, end: Int): Iterator[Int] = range(start, end, 1) /** Create an iterator with elements * <code>e<sub>n+1</sub> = e<sub>n</sub> + step</code> @@ -127,7 +127,7 @@ object Iterator { * @param step the increment value of the iterator (must be positive or negative) * @return the iterator with values in range <code>[start;end)</code>. */ - def range(start: Int, end: Int, step: Int): Range = new Range(start, end, step) + def range(start: Int, end: Int, step: Int): Iterator[Int] = range(start, end, {(_:Int) + step}) /** Create an iterator with elements * <code>e<sub>n+1</sub> = step(e<sub>n</sub>)</code> diff --git a/src/library/scala/Range.scala b/src/library/scala/Range.scala index 1a7a4a0bf0..026e908594 100644 --- a/src/library/scala/Range.scala +++ b/src/library/scala/Range.scala @@ -19,8 +19,8 @@ import Predef._ * Sort of acts like a sequence also (supports length and contains). * For example: * </p><pre> - * <b>val</b> r1 = Iterator.range(0, 10) - * <b>val</b> r2 = Iterator.range(r1.start, r1.end, r1.step + 1) + * <b>val</b> r1 = 0 until 10 + * <b>val</b> r2 = r1.start until r1.end by r1.step + 1 * println(r2.length) // = 5 * </pre> * @@ -31,10 +31,7 @@ class Range(val start: Int, val end: Int, val step: Int) extends RandomAccessSeq if (step == 0) throw new Predef.IllegalArgumentException /** create a new range with the start and end values of this range and a new <code>step</code> */ - def by(step : Int) : Range = this match { - case inclusive : Range.Inclusive => new Range.Inclusive(start, end, step) - case _ => new Range(start, end, step) - } + def by(step : Int) : Range = new Range(start, end, step) lazy val length : Int = { if (start < end && this.step < 0) 0 @@ -59,11 +56,10 @@ class Range(val start: Int, val end: Int, val step: Int) extends RandomAccessSeq def inclusive = new Range.Inclusive(start,end,step) } object Range { - class Inclusive(start : Int, end : Int, by : Int) extends Range(start,end,by) { + class Inclusive(start : Int, end : Int, step : Int) extends Range(start, end, step) { override def apply(idx : Int) : Int = super.apply(idx) override protected def last(base : Int, step : Int) : Int = 1 - // XXX: breaks scala doc! - // override def by(step : Int) : Range = new Inclusive(start, end, step) + override def by(step : Int) : Range = new Inclusive(start, end, step) } } diff --git a/src/library/scala/runtime/RichInt.scala b/src/library/scala/runtime/RichInt.scala index 07827d4287..73b13afa28 100644 --- a/src/library/scala/runtime/RichInt.scala +++ b/src/library/scala/runtime/RichInt.scala @@ -21,13 +21,13 @@ final class RichInt(start: Int) extends Proxy with Ordered[Int] { def compare(that: Int): Int = if (start < that) -1 else if (start > that) 1 else 0 /** See <code>Iterator.range</code>. */ - def until(end: Int): Range = Iterator.range(start, end) + def until(end: Int): Range = new Range(start, end, 1) /** See <code>Iterator.range</code>. */ - def until(end: Int, step: Int): Range = Iterator.range(start, end, step) + def until(end: Int, step: Int): Range = new Range(start, end, step) /** like <code>until</code>, but includes the last index */ - def to(end: Int) = until(end + 1) + def to(end: Int) = new Range.Inclusive(start, end, 1) def min(that: Int): Int = if (start < that) start else that def max(that: Int): Int = if (start > that) start else that |