scala.collection

trait LinearSeqLike

[source: scala/collection/LinearSeqLike.scala]

trait LinearSeqLike[+A, +Repr <: LinearSeqLike[A, Repr]]
extends SeqLike[A, Repr]
Class 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 Seq but overrides several methods with optimized implementations.
Author
Martin Odersky
Matthias Zenger
Version
1.0, 16/07/2003
Since
2.8
Direct Known Subclasses:
LinearSeq, LinearSeq, List, Stream, LinearSeq, MutableList

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) : 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 rightmost n elements from this iterable.
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 slice (from : Int, until : Int) : Repr
A sub-traversable 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 linear sequence whose elements all satisfy the given predicate, and the rest of the linear sequence.
abstract def tail : Repr
Abstract method to be implemented in a subclass
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 takeWhile (p : (A) => Boolean) : Repr
Returns the longest prefix of this traversable whose elements satisfy the predicate p.
protected[this] override def thisCollection : LinearSeq[A]
protected[this] override def toCollection (repr : Repr) : LinearSeq[A]
Methods inherited from SeqLike
size, prefixLength, indexWhere, findIndexOf, indexOf, indexOf, lastIndexOf, lastIndexOf, lastIndexWhere, reverse, reverseMap, reverseIterator, reversedElements, startsWith, startsWith, endsWith, indexOfSeq, indexOfSeq, lastIndexOfSeq, lastIndexOfSeq, contains, union, diff, intersect, removeDuplicates, patch, updated, +:, :+, padTo, sortWith, sortWith, sortBy, toSeq, indices, view, view, hashCode, equals, toString, findLastIndexOf, equalsWith, containsSlice, projection
Methods inherited from IterableLike
elements, toIterable, takeRight, copyToArray, zip, zipAll, zipWithIndex, toStream, canEqual, first, firstOption
Methods inherited from TraversableLike
newBuilder (abstract), repr, nonEmpty, hasDefiniteSize, ++, ++, map, flatMap, filter, filterNot, partialMap, remove, partition, groupBy, /:, :\, reduceLeftOption, reduceRightOption, sum, product, min, max, headOption, lastOption, init, dropWhile, splitAt, 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
Method Details
protected[this] override def thisCollection : LinearSeq[A]
Overrides
SeqLike.thisCollection

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

abstract def isEmpty : Boolean
Abstract method to be implemented in a subclass

abstract def head : A
Abstract method to be implemented in a subclass

abstract def tail : Repr
Abstract method to be implemented in a subclass

def length : Int
Returns the number of elements in the linear sequence.
Overrides
SeqLike.length

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.
Parameters
n - index of the element to return
Returns
the element at position n in this linear sequence.
Throws
Predef.NoSuchElementException - if the linear sequence is too short.
Overrides
SeqLike.apply

override def iterator : Iterator[A]
Returns the elements in the sequence as an iterator

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).
Parameters
f - the treatment to apply to each element.

override def forall(p : (A) => Boolean) : Boolean
Tests if the predicate p is satisfied by all elements in this list.
Parameters
p - the test predicate.
Returns
true iff all elements of this list satisfy the predicate p.

override def exists(p : (A) => Boolean) : Boolean
Tests the existence in this list of an element that satisfies the predicate p.
Parameters
p - the test predicate.
Returns
true iff there exists an element in this list that satisfies the predicate p.

override def count(p : (A) => Boolean) : Int
Count the number of elements in the iterable which satisfy a predicate.
Parameters
p - the predicate for which to count
Returns
the number of elements satisfying 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.
Parameters
p - the predicate
Returns
the first element in the list satisfying p, or None if none exists.

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.
Returns
f(... (f(f(z, a0), a1) ...), an) if the list is [a0, a1, ..., an].

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.
Returns
f(a0, f(a1, f(..., f(an, z)...))) if the list is [a0, a1, ..., an].

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
Parameters
op - The operator to apply
Returns
op(... op(a0,a1), ..., an) if the list has elements a0, a1, ..., an.
Throws
Predef.UnsupportedOperationException - if the list 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.
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 last : A
The last element of this linear sequence.
Throws
Predef.NoSuchElementException - if the linear sequence is empty.

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 dropRight(n : Int) : Repr
Returns the rightmost n elements from this iterable.
Parameters
n - the number of elements to take

override def slice(from : Int, until : Int) : Repr
A sub-traversable 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 traversable 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 takeWhile(p : (A) => Boolean) : Repr
Returns the longest prefix of this traversable whose elements 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 linear sequence whose elements all satisfy the given predicate, and the rest of the linear sequence.
Parameters
p - the test predicate

override def sameElements[B >: A](that : Iterable[B]) : Boolean
Returns true iff the other linear sequence contains the same elements as this one.
Notes
will not terminate for two infinite-sized linear sequences.
Parameters
that - the other 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.
Overrides
SeqLike.lengthCompare

override def isDefinedAt(x : Int) : Boolean
Is this partial function defined for the index x?
Overrides
SeqLike.isDefinedAt

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 linear sequences.
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 satisying a predicate, or -1, if none exists.
Parameters
p - the predicate
Returns
the index of the last element satisfying p, or -1 if such an element does not exist
Overrides
SeqLike.lastIndexWhere