Scala Library
|
|
trait
SequenceTemplate[+A, +This <: IterableTemplate[A, This] with
Sequence[A]]
extends
IterableTemplate[A, This]Sequence[A]
represents sequences of elements
of type A
.
It adds the following methods to class Iterable:
`length`, `lengthCompare`, `apply`, `isDefinedAt`, `segmentLength`, `prefixLength`,
`indexWhere`, `indexOf`, `lastIndexWhere`, `lastIndexOf`, `reverse`, `reverseIterator`,
`startsWith`, `endsWith`, `indexOfSeq`, , `zip`, `zipAll`, `zipWithIndex`.Method Summary | |
abstract def
|
apply
(idx : Int) : A
Returns the elements at position `idx`
|
def
|
contains
(elem : Any) : Boolean
Tests if the given value
elem is a member of this
sequence. |
def
|
containsSlice
[B](that : Sequence[B]) : Boolean
Is
that a slice in this? |
def
|
diff [B >: A, That](that : Sequence[B]) : This |
def
|
endsWith [B](that : Sequence[B]) : Boolean |
override def
|
equals
(that : Any) : Boolean
This method is used to compare the receiver object (
this )
with the argument object (arg0 ) for equivalence. |
def
|
equalsWith [B](that : Sequence[B])(f : (A, B) => Boolean) : Boolean |
def
|
findIndexOf
(p : (A) => Boolean) : Int
Returns index of the first element satisying a predicate, or -1.
|
def
|
findLastIndexOf
(p : (A) => Boolean) : Int
Returns index of the last element satisying a predicate, or -1.
|
def
|
indexOf
[B >: A](elem : B, from : Int) : Int
Returns the index of the first occurence of the specified
object in this iterable object, starting from a start index, or
-1, if none exists.
|
def
|
indexOf
[B >: A](elem : B) : Int
Returns the index of the first occurence of the specified
object in this iterable object.
|
def
|
indexOfSeq [B >: A](that : Sequence[B]) : Int |
def
|
indexOfSeq [B >: A](that : Sequence[B], fromIndex : Int) : Int |
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.
|
def
|
indexWhere
(p : (A) => Boolean) : Int
Returns index of the first element satisfying a predicate, or -1, if none exists.
|
def
|
indices : Range |
def
|
intersect [B >: A, That](that : Sequence[B]) : This |
def
|
isDefinedAt
(x : Int) : Boolean
Is this partial function defined for the index
x ? |
def
|
lastIndexOf
[B >: A](elem : B, end : Int) : Int
Returns the index of the last
occurence of the specified element in this sequence
before or at a given end index,
or -1 if the sequence does not contain this element.
|
def
|
lastIndexOf
[B >: A](elem : B) : Int
Returns the index of the last occurence of the specified element
in this sequence, or -1 if the sequence does not contain this element.
|
def
|
lastIndexOfSeq [B >: A](that : Sequence[B]) : Int |
def
|
lastIndexOfSeq [B >: A](that : Sequence[B], fromIndex : Int) : Int |
def
|
lastIndexWhere
(p : (A) => Boolean) : Int
Returns index of the last element satisying a predicate, or -1, if none exists.
|
def
|
lastIndexWhere
(p : (A) => Boolean, end : Int) : Int
Returns index of the last element not exceeding a given end index
and satisying a predicate, or -1 if none exists.
|
abstract def
|
length
: Int
Returns the length of the sequence.
|
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 .
The method as implemented here does not call length directly; its running time
is O(length min len) instead of O(length). The method should be overwritten
if computing length is cheap. |
def
|
padTo
[B >: A, That](len : Int, elem : B)(implicit bf : BuilderFactory[B, That, This]) : That
Returns a new sequence of given length containing the elements of this sequence followed by zero
or more occurrences of given elements.
|
def
|
patch
[B >: A, That](from : Int, patch : Sequence[B], replaced : Int)(implicit bf : BuilderFactory[B, That, This]) : That
A new sequence, consisting of all elements of current sequence
except that `replaced` elements starting from `from` are replaced
by `patch`.
|
def
|
prefixLength
(p : (A) => Boolean) : Int
Returns length of longest prefix of this seqence
such that every element of the prefix satisfies predicate `p`.
|
override def
|
projection
: SequenceView[A, This]
returns a projection that can be used to call non-strict
filter ,
map , and flatMap methods that build projections
of the collection. |
def
|
removeDuplicates
: This
Builds a new sequence from this sequence in which any duplicates (wrt to ==) removed.
Among duplicate elements, only the first one is retained in the result sequence
|
def
|
reverse
: This
A sequence of type
C consisting of all elements of
this sequence in reverse order. |
def
|
reverseIterator
: Iterator[A]
The elements of this sequence in reversed order
|
def
|
reversedElements : Iterator[A] |
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
|
size
: Int
Should always be
length |
def
|
slice
(from : Int) : Sequence[A]
A sub-sequence starting at index
from
and extending up to the length of the current sequence |
def
|
sortWith
(lt : (A, A) => Boolean) : This
Sort the sequence according to the comparison function
<(e1: a, e2: a) => Boolean ,
which should be true iff e1 is smaller than
e2 .
The sort is stable. That is elements that are equal wrt `lt` appear in the
same order in the sorted sequence as in the original. |
def
|
startsWith
[B](that : Sequence[B], offset : Int) : Boolean
Checks whether the argument sequence is contained at the
specified index within the receiver object.
If the both the receiver object,
this and
the argument, that are infinite sequences
this method may not terminate. |
def
|
startsWith
[B](that : Sequence[B]) : Boolean
Check whether the receiver object starts with the argument sequence.
|
override def
|
toSequence
: Sequence[A]
Overridden for efficiency.
|
override def
|
toString
: java.lang.String
Need to override string, so that it's not the Function1's string that gets mixed in.
|
def
|
union
[B >: A, That](that : Sequence[B])(implicit bf : BuilderFactory[B, That, This]) : That
|
override def
|
view
(from : Int, until : Int) : SequenceView[A, This]
A sub-iterable view starting at index `from`
and extending up to (but not including) index `until`.
|
override def
|
view
: SequenceView[A, This]
Creates a view of this iterable @see IterableView
|
def
|
zip
[A1 >: A, B, That](that : Sequence[B])(implicit bf : BuilderFactory[(A1, B), That, This]) : That
Returns an iterable formed from this iterable and another iterable
by combining corresponding elements in pairs.
If one of the two iterables is longer than the other, its remaining elements are ignored.
|
def
|
zipAll
[B, A1 >: A, That](that : Sequence[B], thisElem : A1, thatElem : B)(implicit bf : BuilderFactory[(A1, B), That, This]) : That
Returns a iterable formed from this iterable and the specified iterable
that by associating each element of the former with
the element at the same position in the latter. |
def
|
zipWithIndex
[A1 >: A, That](implicit bf : BuilderFactory[(A1, Int), That, This]) : That
Zips this iterable with its indices (startiong from 0).
|
Methods inherited from IterableTemplate | |
iterator (abstract), elements, foreach, isEmpty, foldRight, reduceRight, toIterable, head, takeRight, dropRight, sameElements, toStream, first, firstOption, toSeq |
Methods inherited from TraversableTemplate | |
newBuilder (abstract), thisCollection, nonEmpty, hasDefiniteSize, ++, ++, map, flatMap, filter, filterMap, filterNot, remove, partition, groupBy, forall, exists, count, find, foldLeft, /:, :\, reduceLeft, reduceLeftOption, reduceRightOption, headOption, tail, last, lastOption, init, take, drop, slice, takeWhile, dropWhile, span, 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
length : Int
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
.
The method as implemented here does not call length directly; its running time
is O(length min len) instead of O(length). The method should be overwritten
if computing length is cheap.override
def
size : Int
length
x
?
def
zip[A1 >: A, B, That](that : Sequence[B])(implicit
bf : BuilderFactory[(A1, B), That, This]) : That
that -
The iterable providing the second half of each result pair
def
zipAll[B, A1 >: A, That](that : Sequence[B], thisElem : A1, thatElem : B)(implicit
bf : BuilderFactory[(A1, B), That, This]) : That
that
by associating each element of the former with
the element at the same position in the latter.that -
iterable that
may have a different length as the self iterable.thisElem -
element thisElem
is used to fill up the resulting iterable if the self iterable is shorter than
that
thatElem -
element thatElem
is used to fill up the resulting iterable if that
is shorter than
the self iterableSequence((a0,b0), ..., (an,bn), (elem,bn+1),
..., {elem,bm})
when [a0, ..., an] zip
[b0, ..., bm]
is
invoked where m > n
.p -
the predicatefrom -
the start indexp -
the predicatep -
the predicatep -
the predicatefrom -
the start index
def
findIndexOf(p : (A) => Boolean) : Int
elem -
element to search for.elem -
element to search for.elem -
element to search for.elem -
element to search for.end -
the end indexp -
the predicatep
, or -1 if such an element does not existend -
the end indexp -
the predicate
def
reverse : This
C
consisting of all elements of
this sequence in reverse order.this(length - 1), ..., this(0)
If random access is inefficient for the given sequence implementation,
this operation should be overridden.
def
reversedElements : Iterator[A]
this
and
the argument, that
are infinite sequences
this method may not terminate.that
is contained in this
, at the specified index, otherwise falsethat
is a prefix of this
, otherwise falsethat
not contained in this, otherwise the first index where that
is contained.that
not contained in this, otherwise the last index where that
is contained.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
.
Computes the multiset union of this sequence and the given sequence
that
. For example:
val xs = List(1, 1, 2) val ys = List(1, 2, 2, 3) println(xs union ys) // prints "List(1, 1, 2, 1, 2, 2, 3)" println(ys union xs) // prints "List(1, 2, 2, 3, 1, 1, 2)"
that -
the sequence of elements to add to the sequence.that
.
Computes the multiset difference between this sequence and the
given sequence that
. If an element appears more
than once in both sequences, the difference contains m copies
of that element, where m is the difference between the
number of times the element appears in this sequence and the number
of times it appears in that
. For example:
val xs = List(1, 1, 2) val ys = List(1, 2, 2, 3) println(xs diff ys) // prints "List(1)" println(xs -- ys) // prints "List()"
that -
the sequence of elements to remove from this sequence.
Computes the multiset intersection between this sequence and the
given sequence that
; the intersection contains m
copies of an element contained in both sequences, where m is
the smaller of the number of times the element appears in this
sequence or in that
. For example:
val xs = List(1, 1, 2) val ys = List(3, 2, 2, 1) println(xs intersect ys) // prints "List(1, 2)" println(ys intersect xs) // prints "List(2, 1)"
that -
the sequence to intersect.that
.
def
removeDuplicates : This
def
patch[B >: A, That](from : Int, patch : Sequence[B], replaced : Int)(implicit
bf : BuilderFactory[B, That, This]) : That
def
indices : Range
override
def
view : SequenceView[A, This]
override
def
view(from : Int, until : Int) : SequenceView[A, This]
from -
The index of the first element of the sliceuntil -
The index of the element following the slicethis
)
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. override
def
toString : java.lang.String
<(e1: a, e2: a) => Boolean
,
which should be true iff e1
is smaller than
e2
.
The sort is stable. That is elements that are equal wrt `lt` appear in the
same order in the sorted sequence as in the original.lt -
the comparison function<(e1: a, e2: a) => Boolean
.List("Steve", "Tom", "John", "Bob") .sortWith((e1, e2) => (e1 compareTo e2) < 0) = List("Bob", "John", "Steve", "Tom")
def
findLastIndexOf(p : (A) => Boolean) : Int
def
slice(from : Int) : Sequence[A]
from
and extending up to the length of the current sequencefrom -
The index of the first element of the sliceIndexOutOfBoundsException -
if from < 0
def
equalsWith[B](that : Sequence[B])(f : (A, B) => Boolean) : Boolean
def
containsSlice[B](that : Sequence[B]) : Boolean
that
a slice in this?override
def
projection : SequenceView[A, This]
filter
,
map
, and flatMap
methods that build projections
of the collection.
Scala Library
|
|