scala

class Range

[source: scala/Range.scala]

class Range(val start : Int, val end : Int, val step : Int)
extends scala.RangeToString[Int]

The Range class represents integer values in range [start;end) with non-zero step value step. Sort of acts like a sequence also (supports length and contains). For example:

     val r1 = 0 until 10
     val r2 = r1.start until r1.end by r1.step + 1
     println(r2.length) // = 5
  
Author
Martin Odersky
Version
2.8
Direct Known Subclasses:
Range.Inclusive

Value Summary
lazy val length : Int
Returns the length of the sequence.
Method Summary
final def apply (idx : Int) : Int
Returns the elements at position `idx`
def by (step : Int) : Range
Create a new range with the start and end values of this range and a new step.
def contains (x : Int) : Boolean
override def equals (other : Any) : Boolean
This method is used to compare the receiver object (this) with the argument object (arg0) for equivalence.
override final def foreach [U](f : (Int) => U) : Unit
Apply a function f to all elements of this traversable object.
override def hashCode : Int
Returns a hash code value for the object.
def inclusive : Range
protected def underlying : Vector[Int]
Methods inherited from scala.RangeToString
scala.RangeToString.toString
Methods inherited from VectorViewTemplate
newAppended, newMapped, newFlatMapped, newFiltered, newSliced, newDroppedWhile, newTakenWhile, newReversed, newPatched, newZipped
Methods inherited from SequenceViewTemplate
reverse, patch, padTo, zip, zipWithIndex, zipAll
Methods inherited from TraversableViewTemplate
newBuilder, force, ++, ++, map, flatMap, filter, init, drop, take, slice, dropWhile, takeWhile, span, splitAt
Methods inherited from Vector
companion
Methods inherited from VectorTemplate
iterator, isEmpty, forall, exists, find, foldLeft, foldRight, reduceLeft, reduceRight, head, tail, last, takeRight, dropRight, sameElements, copyToArray, lengthCompare, segmentLength, indexWhere, lastIndexWhere, reverseIterator, startsWith, endsWith, view, view
Methods inherited from SequenceTemplate
size, isDefinedAt, prefixLength, indexWhere, findIndexOf, indexOf, indexOf, lastIndexOf, lastIndexOf, lastIndexWhere, reversedElements, startsWith, indexOfSeq, indexOfSeq, lastIndexOfSeq, lastIndexOfSeq, contains, union, diff, intersect, removeDuplicates, toSequence, indices, sortWith, findLastIndexOf, slice, equalsWith, containsSlice, projection
Methods inherited from IterableTemplate
elements, toIterable, toStream, first, firstOption, toSeq
Methods inherited from TraversableClass
genericBuilder, unzip, flatten, transpose
Methods inherited from TraversableTemplate
thisCollection, nonEmpty, hasDefiniteSize, filterMap, filterNot, remove, partition, groupBy, count, /:, :\, reduceLeftOption, reduceRightOption, headOption, lastOption, copyToBuffer, copyToArray, toArray, toList, toSet, mkString, mkString, mkString, addString, addString, addString, stringPrefix
Methods inherited from PartialFunction
orElse, andThen
Methods inherited from Function1
compose
Methods inherited from AnyRef
getClass, clone, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized
Methods inherited from Any
==, !=, isInstanceOf, asInstanceOf
Value Details
lazy val length : Int
Returns the length of the sequence.
Returns
the sequence length.

Method Details
protected def underlying : Vector[Int]

def by(step : Int) : Range
Create a new range with the start and end values of this range and a new step.

override final def foreach[U](f : (Int) => U) : Unit
Apply a function f to all elements of this traversable 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.

@inline

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

def contains(x : Int) : Boolean

def inclusive : Range

override def equals(other : Any) : Boolean
This method is used to compare the receiver object (this) with the argument object (arg0) for equivalence.

The default implementations of this method is an equivalence relation:

  • It is reflexive: for any instance x of type Any, x.equals(x) should return true.
  • It is symmetric: for any instances x and y of type Any, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any instances x, y, and z of type AnyRef if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.

If you override this method, you should verify that your implementation remains an equivalence relation. Additionally, when overriding this method it is often necessary to override hashCode to ensure that objects that are "equal" (o1.equals(o2) returns true) hash to the same Int (o1.hashCode.equals(o2.hashCode)).

Parameters
arg0 - the object to compare against this object for equality.
Returns
true if the receiver object is equivalent to the argument; false otherwise.


override def 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.