scala.collection

trait IndexedSeqLike

[source: scala/collection/IndexedSeqLike.scala]

trait IndexedSeqLike[+A, +Repr]
extends SeqLike[A, Repr]
Sequences that support O(1) element access and O(1) length computation. This class does not add any methods to Seq but overrides several methods with optimized implementations.
Author
Sean McDirmid
Martin Odersky
Version
2.8
Since
2.8
Direct Known Subclasses:
IndexedSeq, IndexedSeqViewLike, IndexedSeq, StringLike, IndexedSeqLike, RichString

Method Summary
override def copyToArray [B >: A](xs : Array[B], start : Int, len : Int) : Unit
Fills the given array xs with at most `len` elements of this iterable starting at position `start`. Copying will stop once either the end of the current iterable is reached or `len` elements have been copied or the end of the array is reached.
override def drop (n : Int) : Repr
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) : Repr
Returns the iterable wihtout its rightmost n elements.
override def dropWhile (p : (A) => Boolean) : Repr
Returns the longest suffix of this traversable whose first element does not satisfy the predicate p.
override def endsWith [B](that : Seq[B]) : Boolean
override def exists (p : (A) => Boolean) : Boolean
Return true iff there is an element in this iterable for which the given predicate `p` yields true.
override def find (p : (A) => Boolean) : Option[A]
Find and return the first element of the iterable object satisfying a predicate, if any.
override def foldLeft [B](z : B)(op : (B, A) => B) : B
Combines the elements of this traversable object together using the binary function f, from left to right, and starting with the value z.
override def foldRight [B](z : B)(op : (A, B) => B) : B
Combines the elements of this iterable together using the binary function f, from right to left, and starting with the value z.
override def forall (p : (A) => Boolean) : Boolean
Return true iff the given predicate `p` yields true for all elements of this iterable.
override def foreach [U](f : (A) => U) : Unit
Apply a function f to all elements of this iterable object.
override def head : A
The first element of this iterable.
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 init : Repr
a traversable consisting of all elements of this traversable except the last one.
override def isEmpty : Boolean
Does this iterable contain no elements?
override def iterator : Iterator[A]
Creates a new iterator over all elements contained in this iterable object.
override def last : A
The last element of this traversable.
override 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.
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. 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 reduceLeft [B >: A](op : (B, A) => B) : B
Combines the elements of this traversable object 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 reverse : Repr
A sequence of type C consisting of all elements of this sequence in reverse order.
override def reverseIterator : Iterator[A]
The elements of this sequence in reversed order
override def sameElements [B >: A](that : Iterable[B]) : Boolean
Checks if the other iterable object 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 slice (from : Int, until : Int) : Repr
A sub-iterable starting at index `from` and extending up to (but not including) index `until`.
override def span (p : (A) => Boolean) : (Repr, Repr)
Returns a pair consisting of the longest prefix of the traversable whose elements all satisfy the given predicate, and the rest of the traversable.
override def splitAt (n : Int) : (Repr, Repr)
Split the traversable at a given point and return the two parts thus created.
override def startsWith [B](that : Seq[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.
override def tail : Repr
a traversable consisting of all elements of this traversable except the first one.
override def take (n : Int) : Repr
Return an iterable consisting only of the first n elements of this iterable, or else the whole iterable, if it has less than n elements.
override def takeRight (n : Int) : Repr
Returns the rightmost n elements from this iterable.
override def takeWhile (p : (A) => Boolean) : Repr
Returns the longest prefix of this iterable whose elements satisfy the predicate p.
protected[this] override def thisCollection : IndexedSeq[A]
protected[this] override def toCollection (repr : Repr) : IndexedSeq[A]
override def view (from : Int, until : Int) : IndexedSeqView[A, Repr]
A sub-iterable view starting at index `from` and extending up to (but not including) index `until`.
override def view : IndexedSeqView[A, Repr]
Creates a view of this iterable @see IterableView
override def zip [A1 >: A, B, That](that : Iterable[B])(implicit bf : CanBuildFrom[Repr, (A1, B), That]) : 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.
override def zipWithIndex [A1 >: A, That](implicit bf : CanBuildFrom[Repr, (A1, Int), That]) : That
Zips this iterable with its indices (startiong from 0).
Methods inherited from SeqLike
length (abstract), apply (abstract), size, isDefinedAt, prefixLength, indexWhere, findIndexOf, indexOf, indexOf, lastIndexOf, lastIndexOf, lastIndexWhere, reverseMap, reversedElements, startsWith, indexOfSeq, indexOfSeq, lastIndexOfSeq, lastIndexOfSeq, contains, union, diff, intersect, removeDuplicates, patch, updated, +:, :+, padTo, sortWith, sortWith, sortBy, toSeq, indices, hashCode, equals, toString, findLastIndexOf, equalsWith, containsSlice, projection
Methods inherited from IterableLike
elements, toIterable, zipAll, toStream, canEqual, first, firstOption
Methods inherited from TraversableLike
newBuilder (abstract), 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
Class Summary
protected class Elements (start : Int, end : Int) extends BufferedIterator[A]
The iterator returned by the iterator method
Method Details
protected[this] override def thisCollection : IndexedSeq[A]
Overrides
SeqLike.thisCollection

protected[this] override def toCollection(repr : Repr) : IndexedSeq[A]
Overrides
SeqLike.toCollection

override def iterator : Iterator[A]
Creates a new iterator over all elements contained in this iterable object.
Returns
the new iterator

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

override def foreach[U](f : (A) => 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.

override def forall(p : (A) => Boolean) : Boolean
Return true iff the given predicate `p` yields true for all elements of this iterable.
Notes
May not terminate for infinite-sized collections.
Parameters
p - the predicate

override def exists(p : (A) => Boolean) : Boolean
Return true iff there is an element in this iterable for which the given predicate `p` yields true.
Notes
May not terminate for infinite-sized collections.
Parameters
p - the predicate

override def find(p : (A) => Boolean) : Option[A]
Find and return the first element of the iterable object satisfying a predicate, if any.
Notes
may not terminate for infinite-sized collections.
Might return different results for different runs, unless this iterable is ordered.
Parameters
p - the predicate
Returns
an option containing the first element in the iterable object satisfying p, or None if none exists.

override def foldLeft[B](z : B)(op : (B, A) => B) : B
Combines the elements of this traversable object together using the binary function f, from left to right, and starting with the value z.
Notes
Will not terminate for infinite-sized collections.
Might return different results for different runs, unless this traversable is ordered, or the operator is associative and commutative.
Returns
f(... (f(f(z, a0), a1) ...), an) if the traversable is [a0, a1, ..., an].

override def foldRight[B](z : B)(op : (A, B) => B) : B
Combines the elements of this iterable together using the binary function f, from right to left, and starting with the value z.
Notes
Will not terminate for infinite-sized collections.
Might return different results for different runs, unless this iterable is ordered, or the operator is associative and commutative.
Returns
f(a0, f(a1, f(..., f(an, z)...))) if the iterable is [a0, a1, ..., an].

override def reduceLeft[B >: A](op : (B, A) => B) : B
Combines the elements of this traversable object together using the binary operator op, from left to right
Notes
Will not terminate for infinite-sized collections.
Might return different results for different runs, unless this traversable is ordered, or the operator is associative and commutative.
Parameters
op - The operator to apply
Returns
op(... op(a0,a1), ..., an) if the traversable object has elements a0, a1, ..., an.
Throws
Predef.UnsupportedOperationException - if the traversable object is empty.

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
Notes
Will not terminate for infinite-sized collections.
Might return different results for different runs, unless this iterable is ordered, or the operator is associative and commutative.
Parameters
op - The operator to apply
Returns
a0 op (... op (an-1 op an)...) if the iterable object has elements a0, a1, ..., an.
Throws
Predef.UnsupportedOperationException - if the iterator is empty.

override def zip[A1 >: A, B, That](that : Iterable[B])(implicit bf : CanBuildFrom[Repr, (A1, B), That]) : 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.
Parameters
that - The iterable providing the second half of each result pair

override def zipWithIndex[A1 >: A, That](implicit bf : CanBuildFrom[Repr, (A1, Int), That]) : That
Zips this iterable with its indices (startiong from 0).

override def slice(from : Int, until : Int) : Repr
A sub-iterable starting at index `from` and extending up to (but not including) index `until`.
Notes
c.slice(from, to) is equivalent to (but possibly more efficient than) c.drop(from).take(to - from)
Might return different results for different runs, unless this iterable is ordered
Parameters
from - The index of the first element of the returned subsequence
until - The index of the element following the returned subsequence

override def head : A
The first element of this iterable.
Notes
Might return different results for different runs, unless this iterable is ordered
Throws
Predef.NoSuchElementException - if the iterable is empty.

override def tail : Repr
a traversable consisting of all elements of this traversable except the first one.
Notes
Might return different results for different runs, unless this traversable is ordered

override def last : A
The last element of this traversable.
Throws
Predef.NoSuchElementException - if the traversable is empty.
Notes
Might return different results for different runs, unless this traversable is ordered

override def init : Repr
a traversable consisting of all elements of this traversable except the last one.
Throws
Predef.UnsupportedOperationException - if the stream is empty.
Notes
Might return different results for different runs, unless this traversable is ordered

override def take(n : Int) : Repr
Return an iterable consisting only of the first n elements of this iterable, or else the whole iterable, if it has less than n elements.
Parameters
n - the number of elements to take
Notes
Might return different results for different runs, unless this iterable is ordered

override def drop(n : Int) : Repr
Returns this traversable without its n first elements If this traversable has less than n elements, the empty traversable is returned.
Parameters
n - the number of elements to drop
Returns
the new traversable
Notes
Might return different results for different runs, unless this traversable is ordered

override def takeRight(n : Int) : Repr
Returns the rightmost n elements from this iterable.
Parameters
n - the number of elements to take
Notes
Might return different results for different runs, unless this iterable is ordered

override def dropRight(n : Int) : Repr
Returns the iterable wihtout its rightmost n elements.
Parameters
n - the number of elements to take
Notes
Might return different results for different runs, unless this iterable is ordered

override def splitAt(n : Int) : (Repr, Repr)
Split the traversable at a given point and return the two parts thus created.
Parameters
n - the position at which to split
Returns
a pair of traversables composed of the first n elements, and the other elements.
Notes
Might return different results for different runs, unless this traversable is ordered

override def takeWhile(p : (A) => Boolean) : Repr
Returns the longest prefix of this iterable whose elements satisfy the predicate p.
Parameters
p - the test predicate.
Notes
Might return different results for different runs, unless this iterable is ordered

override def dropWhile(p : (A) => Boolean) : Repr
Returns the longest suffix of this traversable whose first element does not satisfy the predicate p.
Parameters
p - the test predicate.
Notes
Might return different results for different runs, unless this traversable is ordered

override def span(p : (A) => Boolean) : (Repr, Repr)
Returns a pair consisting of the longest prefix of the traversable whose elements all satisfy the given predicate, and the rest of the traversable.
Parameters
p - the test predicate
Returns
a pair consisting of the longest prefix of the traversable whose elements all satisfy p, and the rest of the traversable.
Notes
Might return different results for different runs, unless this traversable is ordered

override def sameElements[B >: A](that : Iterable[B]) : Boolean
Checks if the other iterable object contains the same elements as this one.
Notes
will not terminate for infinite-sized iterables.
Might return different results for different runs, unless this iterable is ordered
Parameters
that - the other iterable
Returns
true, iff both iterables contain the same elements in the same order.

override def copyToArray[B >: A](xs : Array[B], start : Int, len : Int) : Unit
Fills the given array xs with at most `len` elements of this iterable starting at position `start`. Copying will stop once either the end of the current iterable is reached or `len` elements have been copied or the end of the array is reached.
Notes
Will not terminate for infinite-sized collections.
Parameters
xs - the array to fill.
start - starting index.
len - number of elements to copy

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. 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.
Overrides
SeqLike.lengthCompare

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`.
Notes
may not terminate for infinite-sized collections.
Parameters
p - the predicate
from - the start index
Overrides
SeqLike.segmentLength

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.
Notes
may not terminate for infinite-sized collections.
Parameters
p - the predicate
from - the start index
Overrides
SeqLike.indexWhere

override 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.
Parameters
end - the end index
p - the predicate
Overrides
SeqLike.lastIndexWhere

override def reverse : Repr
A sequence of type C consisting of all elements of this sequence in reverse order.
Overrides
SeqLike.reverse

override def reverseIterator : Iterator[A]
The elements of this sequence in reversed order
Overrides
SeqLike.reverseIterator

override def startsWith[B](that : Seq[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.
Returns
true if that is contained in this, at the specified index, otherwise false
See Also
String.startsWith
Overrides
SeqLike.startsWith

override def endsWith[B](that : Seq[B]) : Boolean
Returns
true if this sequence end with that sequence
See Also
String.endsWith
Overrides
SeqLike.endsWith

override def view : IndexedSeqView[A, Repr]
Creates a view of this iterable @see IterableView
Overrides
SeqLike.view

override def view(from : Int, until : Int) : IndexedSeqView[A, Repr]
A sub-iterable view starting at index `from` and extending up to (but not including) index `until`.
Parameters
from - The index of the first element of the slice
until - The index of the element following the slice
Notes
The difference between `view` and `slice` is that `view` produces a view of the current iterable, whereas `slice` produces a new iterable.
Might return different results for different runs, unless this iterable is ordered
view(from, to) is equivalent to view.slice(from, to)
Overrides
SeqLike.view