scala.collection.immutable

class NumericRange

[source: scala/collection/immutable/NumericRange.scala]

abstract class NumericRange[+T](val start : T, val end : T, val step : T, val isInclusive : Boolean, implicit num : Integral[T])
extends IndexedSeq[T]

NumericRange is a more generic version of the Range class which works with arbitrary types. It must be supplied with an Integral implementation of the range type. Factories for likely types include Range.BigInt, Range.Long, and Range.BigDecimal. Range.Int exists for completeness, but the Int-based scala.Range should be more performant.

     val r1 = new Range(0, 100, 1)
     val veryBig = Math.MAX_INT.toLong + 1
     val r2 = Range.Long(veryBig, veryBig + 100, 1)
     assert(r1 sameElements r2.map(_ - veryBig))
  
Author
Paul Phillips
Version
2.8
Direct Known Subclasses:
NumericRange.Inclusive, NumericRange.Exclusive

Value Summary
override lazy val hashCode : Int
Returns a hash code value for the object.
Method Summary
def apply (idx : Int) : T
Returns the elements at position `idx`
def by [U >: T](newStep : U)(implicit unum : Integral[U]) : NumericRange[U]
Create a new range with the start and end values of this range and a new step.
override def contains (x : Any) : Boolean
Tests if the given value elem is a member of this sequence.
def containsTyped [U >: T](x : U)(implicit unum : Integral[U]) : Boolean
abstract def copy [U >: T](start : U, end : U, step : U)(implicit unum : Integral[U]) : NumericRange[U]
Create a copy of this range.
override def equals (other : Any) : Boolean
The equality method defined in `AnyRef`.
override def foreach [U](f : (T) => U) : Unit
Apply a function f to all elements of this iterable object.
def genericLength : T
override def isEmpty : Boolean
Does this iterable contain no elements?
def length : Int
Returns the length of the sequence.
protected def limitTest [U >: T](x : U)(implicit unum : Integral[U]) : Boolean
override def toString : java.lang.String
Need to override string, so that it's not the Function1's string that gets mixed in.
protected def underlying : IndexedSeq[T]
Methods inherited from IndexedSeq
companion
Methods inherited from IndexedSeqLike
thisCollection, toCollection, iterator, forall, exists, find, foldLeft, foldRight, reduceLeft, reduceRight, zip, zipWithIndex, slice, head, tail, last, init, take, drop, takeRight, dropRight, splitAt, takeWhile, dropWhile, span, sameElements, copyToArray, lengthCompare, segmentLength, indexWhere, lastIndexWhere, reverse, reverseIterator, startsWith, endsWith, view, view
Methods inherited from SeqLike
size, isDefinedAt, prefixLength, indexWhere, findIndexOf, indexOf, indexOf, lastIndexOf, lastIndexOf, lastIndexWhere, reverseMap, reversedElements, startsWith, indexOfSeq, indexOfSeq, lastIndexOfSeq, lastIndexOfSeq, union, diff, intersect, removeDuplicates, patch, updated, +:, :+, padTo, sortWith, sortWith, sortBy, toSeq, indices, findLastIndexOf, equalsWith, containsSlice, projection
Methods inherited from PartialFunction
orElse, andThen
Methods inherited from Function1
compose
Methods inherited from IterableLike
elements, toIterable, zipAll, toStream, canEqual, first, firstOption
Methods inherited from GenericTraversableTemplate
newBuilder, genericBuilder, unzip, flatten, transpose
Methods inherited from TraversableLike
repr, nonEmpty, hasDefiniteSize, ++, ++, map, flatMap, filter, filterNot, partialMap, remove, partition, groupBy, count, /:, :\, reduceLeftOption, reduceRightOption, sum, product, min, max, headOption, lastOption, copyToBuffer, copyToArray, toArray, toList, toIndexedSeq, toSet, mkString, mkString, mkString, addString, addString, addString, stringPrefix, withFilter
Methods inherited from AnyRef
getClass, clone, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized
Methods inherited from Any
==, !=, isInstanceOf, asInstanceOf
Value Details
override lazy val hashCode : Int
Returns a hash code value for the object.

The default hashing algorithm is platform dependent. Note that it is allowed for two objects to have identical hash codes (o1.hashCode.equals(o2.hashCode)) yet not be equal (o1.equals(o2) returns false). A degenerate implementation could always return 0. However, it is required that if two objects are equal (o1.equals(o2) returns true) that they have identical hash codes (o1.hashCode.equals(o2.hashCode)). Therefore, when overriding this method, be sure to verify that the behavior is consistent with the equals method.

Returns
the hash code value for the object.


Method Details
protected def limitTest[U >: T](x : U)(implicit unum : Integral[U]) : Boolean

protected def underlying : IndexedSeq[T]

def by[U >: T](newStep : U)(implicit unum : Integral[U]) : NumericRange[U]
Create a new range with the start and end values of this range and a new step.

abstract def copy[U >: T](start : U, end : U, step : U)(implicit unum : Integral[U]) : NumericRange[U]
Create a copy of this range.

override def foreach[U](f : (T) => U) : Unit
Apply a function f to all elements of this iterable object.
Parameters
f - A function that is applied for its side-effect to every element. The result (of arbitrary type U) of function `f` is discarded.
Notes
This method underlies the implementation of most other bulk operations. Implementing `foreach` with `iterator` is often suboptimal. So `foreach` should be overridden in concrete collection classes if a more efficient implementation is available.

def genericLength : T

def length : Int
Returns the length of the sequence.

override def isEmpty : Boolean
Does this iterable contain no elements?

def apply(idx : Int) : T
Returns the elements at position `idx`

def containsTyped[U >: T](x : U)(implicit unum : Integral[U]) : Boolean

override def contains(x : Any) : Boolean
Tests if the given value elem is a member of this sequence.
Parameters
elem - element whose membership has to be tested.
Returns
true iff there is an element of this sequence which is equal (w.r.t. ==) to elem.

override def equals(other : Any) : Boolean
The equality method defined in `AnyRef`.

override def toString : java.lang.String
Need to override string, so that it's not the Function1's string that gets mixed in.