diff options
Diffstat (limited to 'src/library/scala/collection/immutable/NumericRange.scala')
-rw-r--r-- | src/library/scala/collection/immutable/NumericRange.scala | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/library/scala/collection/immutable/NumericRange.scala b/src/library/scala/collection/immutable/NumericRange.scala index fb5c7221dc..a548b62533 100644 --- a/src/library/scala/collection/immutable/NumericRange.scala +++ b/src/library/scala/collection/immutable/NumericRange.scala @@ -42,7 +42,7 @@ import generic._ abstract class NumericRange[T] (val start: T, val end: T, val step: T, val isInclusive: Boolean) (implicit num: Integral[T]) -extends IndexedSeq[T] with Serializable { +extends IndexedSeq[T] with Parallelizable[parallel.immutable.ParNumericRange[T]] with Serializable { /** Note that NumericRange must be invariant so that constructs * such as "1L to 10 by 5" do not infer the range type as AnyVal. */ @@ -57,6 +57,8 @@ extends IndexedSeq[T] with Serializable { if (length == 0) Nil.last else locationAfterN(length - 1) + def par = new parallel.immutable.ParNumericRange(this) + /** Create a new range with the start and end values of this range and * a new `step`. */ @@ -107,6 +109,18 @@ extends IndexedSeq[T] with Serializable { // based on the given value. private def newEmptyRange(value: T) = NumericRange(value, value, step) + final override def take(n: Int): NumericRange[T] = ( + if (n <= 0 || length == 0) newEmptyRange(start) + else if (n >= length) this + else new NumericRange.Inclusive(start, locationAfterN(n - 1), step) + ) + + final override def drop(n: Int): NumericRange[T] = ( + if (n <= 0 || length == 0) this + else if (n >= length) newEmptyRange(end) + else copy(locationAfterN(n), end, step) + ) + def apply(idx: Int): T = { if (idx < 0 || idx >= length) throw new IndexOutOfBoundsException(idx.toString) else locationAfterN(idx) |