Scala Library
|
|
scala/GenericRange.scala
]
abstract
class
GenericRange[T](val
start : T, val
end : T, val
step : T, val
isInclusive : Boolean, implicit
num : Integral[T])
extends
scala.RangeToString[T] with
Hashable
GenericRange
is a generified 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))
Value Summary | |
lazy val
|
genericLength : T |
val
|
hashValues : List[T] |
lazy val
|
length
: Int
Returns the length of the sequence.
|
Method Summary | |
def
|
* (mult : T) : GenericRange[T] |
def
|
+ (shift : T) : GenericRange[T] |
def
|
-
(shift : T) : GenericRange[T]
Shift or multiply the entire range by some constant.
|
def
|
apply
(idx : Int) : T
Returns the elements at position `idx`
|
def
|
applyAt (idx : T) : T |
def
|
by
(newStep : T) : GenericRange[T]
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. |
abstract def
|
copy
(start : T, end : T, step : T) : GenericRange[T]
Create a copy of this range.
|
override def
|
equals
(other : Any) : Boolean
This method is used to compare the receiver object (
this )
with the argument object (arg0 ) for equivalence. |
override def
|
foreach
[U](f : (T) => U) : Unit
Apply a function
f to all elements of this
traversable object. |
protected def
|
underlying : Vector[T] |
Methods inherited from Hashable | |
hashSeed, hashCode, equalHashValues |
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, 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
genericLength : T
lazy val
length : Int
Method Details |
def
by(newStep : T) : GenericRange[T]
step
.abstract
def
copy(start : T, end : T, step : T) : GenericRange[T]
def
-(shift : T) : GenericRange[T]
def
+(shift : T) : GenericRange[T]
def
*(mult : T) : GenericRange[T]
f
to all elements of this
traversable object.f -
A function that is applied for its side-effect to every element. The result (of arbitrary type U) of function `f` is discarded.elem
is a member of this
sequence.elem -
element whose membership has to be tested.true
iff there is an element of this sequence which is equal (w.r.t. ==
) to elem
.this
)
with the argument object (arg0
) for equivalence.
The default implementations of this method is an equivalence relation:
x
of type Any
,
x.equals(x)
should return true
.x
and y
of type
Any
, x.equals(y)
should return true
if and only
if y.equals(x)
returns true
.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)
).
arg0 -
the object to compare against this object for equality.true
if the receiver object is equivalent to the argument; false
otherwise.
Scala Library
|
|