Scala Library
|
|
trait
LinearSequenceTemplate[+A, +This <: LinearSequenceTemplate[A, This] with
LinearSequence[A]]
extends
SequenceTemplate[A, This]Linear[A]
represents linear sequences of elements.
For such sequences `isEmpty`, `head` and `tail` are guaranteed to be
efficient constant time (or near so) operations.
It does not add any methods to Sequence
but overrides
several methods with optimized implementations.Method Summary | |
def
|
apply
(n : Int) : A
Returns the
n -th element of this linear sequence. The first element
(head of the linear sequence) is at position 0. |
override def
|
count
(p : (A) => Boolean) : Int
Count the number of elements in the iterable which satisfy a predicate.
|
override def
|
drop
(n : Int) : This
Returns this traversable without its
n first elements
If this traversable has less than n elements, the empty
traversable is returned. |
override def
|
dropRight
(n : Int) : This
Returns the rightmost
n elements from this iterable. |
override def
|
equals
(that : Any) : Boolean
This method is used to compare the receiver object (
this )
with the argument object (arg0 ) for equivalence. |
override def
|
exists
(p : (A) => Boolean) : Boolean
Tests the existence in this list of an element that satisfies the
predicate
p . |
override def
|
find
(p : (A) => Boolean) : Option[A]
Find and return the first element of the list satisfying a
predicate, if any.
|
override def
|
foldLeft
[B](z : B)(f : (B, A) => B) : B
Combines the elements of this list together using the binary
function
f , from left to right, and starting with
the value z . |
override def
|
foldRight
[B](z : B)(f : (A, B) => B) : B
Combines the elements of this list together using the binary
function
f , from right to left, and starting with
the value z . |
override def
|
forall
(p : (A) => Boolean) : Boolean
Tests if the predicate
p is satisfied by all elements
in this list. |
override def
|
foreach
[B](f : (A) => B) : Unit
Apply the given function
f to each element of this linear sequence
(while respecting the order of the elements). |
abstract def
|
head
: A
Abstract method to be implemented in a subclass
|
override def
|
indexWhere
(p : (A) => Boolean, from : Int) : Int
Returns index of the first element starting from a start index
satisying a predicate, or -1, if none exists.
|
override def
|
isDefinedAt
(x : Int) : Boolean
Is this partial function defined for the index
x ? |
abstract def
|
isEmpty
: Boolean
Abstract method to be implemented in a subclass
|
override def
|
iterator
: Iterator[A]
Returns the elements in the sequence as an iterator
|
override def
|
last
: A
The last element of this linear sequence.
|
override def
|
lastIndexWhere
(p : (A) => Boolean, end : Int) : Int
Returns index of the last element satisying a predicate, or -1, if none exists.
|
def
|
length
: Int
Returns the number of elements in the linear sequence.
|
override def
|
lengthCompare
(len : Int) : Int
Result of comparing
length with operand len .
returns x where
x < 0 iff this.length < len
x == 0 iff this.length == len
x > 0 iff this.length > len . |
override def
|
reduceLeft
[B >: A](f : (B, A) => B) : B
Combines the elements of this list together using the binary
operator
op , from left to right |
override def
|
reduceRight
[B >: A](op : (A, B) => B) : B
Combines the elements of this iterable object together using the binary
operator
op , from right to left |
override def
|
sameElements
[B >: A](that : Iterable[B]) : Boolean
Returns true iff the other linear sequence contains the same elements as this one.
|
override def
|
segmentLength
(p : (A) => Boolean, from : Int) : Int
Returns length of longest segment starting from a start index `from`
such that every element of the segment satisfies predicate `p`.
|
override def
|
span
(p : (A) => Boolean) : (This, This)
Returns a pair consisting of the longest prefix of the linear sequence whose
elements all satisfy the given predicate, and the rest of the linear sequence.
|
abstract def
|
tail
: This
Abstract method to be implemented in a subclass
|
override def
|
take
(n : Int) : This
Return an traversable consisting only of the first
n
elements of this traversable, or else the whole traversable, if it has less
than n elements. |
Methods inherited from SequenceTemplate | |
size, zip, zipAll, zipWithIndex, prefixLength, indexWhere, findIndexOf, indexOf, indexOf, lastIndexOf, lastIndexOf, lastIndexWhere, reverse, reverseIterator, reversedElements, startsWith, startsWith, endsWith, indexOfSeq, indexOfSeq, lastIndexOfSeq, lastIndexOfSeq, contains, union, diff, intersect, removeDuplicates, patch, padTo, toSequence, indices, view, view, toString, sortWith, findLastIndexOf, slice, equalsWith, containsSlice, projection |
Methods inherited from IterableTemplate | |
elements, toIterable, takeRight, toStream, first, firstOption, toSeq |
Methods inherited from TraversableTemplate | |
newBuilder (abstract), thisCollection, nonEmpty, hasDefiniteSize, ++, ++, map, flatMap, filter, filterMap, filterNot, remove, partition, groupBy, /:, :\, reduceLeftOption, reduceRightOption, headOption, lastOption, init, slice, takeWhile, dropWhile, splitAt, copyToBuffer, copyToArray, copyToArray, toArray, toList, toSet, mkString, mkString, mkString, addString, addString, addString, stringPrefix |
Methods inherited from AnyRef | |
getClass, hashCode, clone, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized |
Methods inherited from Any | |
==, !=, isInstanceOf, asInstanceOf |
Method Details |
abstract
def
isEmpty : Boolean
abstract
def
head : A
abstract
def
tail : This
def
length : Int
n
-th element of this linear sequence. The first element
(head of the linear sequence) is at position 0.n -
index of the element to returnn
in this linear sequence.f
to each element of this linear sequence
(while respecting the order of the elements).f -
the treatment to apply to each element.p
is satisfied by all elements
in this list.p -
the test predicate.true
iff all elements of this list satisfy the predicate p
.p
.p -
the test predicate.true
iff there exists an element in this list that satisfies the predicate p
.p -
the predicate for which to countp
.p -
the predicatep
, or None
if none exists.f
, from left to right, and starting with
the value z
.f(... (f(f(z, a0), a1) ...), an)
if the list is
[a0, a1, ..., an]
.f
, from right to left, and starting with
the value z
.f(a0, f(a1, f(..., f(an, z)...)))
if the list is [a0, a1, ..., an]
.op
, from left to rightop -
The operator to applyop(... op(a0,a1), ..., an)
if the list has elements
a0, a1, ..., an
.op
, from right to leftop -
The operator to applya0 op (... op (an-1 op an)...)
if the iterable object has elements a0, a1, ...,
an
.override
def
last : A
n
elements of this traversable, or else the whole traversable, if it has less
than n
elements.n -
the number of elements to taken
first elements
If this traversable has less than n
elements, the empty
traversable is returned.n -
the number of elements to dropn
elements from this iterable.n -
the number of elements to takep -
the test predicatethat -
the other linear sequencelength
with operand len
.
returns x
where
x < 0
iff this.length < len
x == 0
iff this.length == len
x > 0
iff this.length > len
.x
?p -
the predicatefrom -
the start indexp -
the predicatefrom -
the start indexp -
the predicatep
, or -1 if such an element does not existthis
)
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
|
|