scala.collection.generic

trait LinearSequenceTemplate

[source: scala/collection/generic/LinearSequenceTemplate.scala]

trait LinearSequenceTemplate[+A, +This <: LinearSequenceTemplate[A, This] with LinearSequence[A]]
extends SequenceTemplate[A, This]
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 Sequence but overrides several methods with optimized implementations.
Author
Martin Odersky
Matthias Zenger
Version
1.0, 16/07/2003
Direct Known Subclasses:
LinearSequence, LinearSequence, List, Stream, LinearSequence, 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) : 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 method to be implemented in a subclass

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

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

def length : Int
Returns the number of elements in the linear sequence.
Overrides
SequenceTemplate.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
SequenceTemplate.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) : 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.
Parameters
n - the number of elements to take
Notes
Might return different results for different runs, unless this traversable is ordered

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

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.
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
SequenceTemplate.lengthCompare

override def isDefinedAt(x : Int) : Boolean
Is this partial function defined for the index x?
Overrides
SequenceTemplate.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
SequenceTemplate.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
SequenceTemplate.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
SequenceTemplate.lastIndexWhere

override def equals(that : Any) : Boolean
This method is used to compare the receiver object (this) with the argument object (arg0) for equivalence.

The default implementations of this method is an equivalence relation:

  • It is reflexive: for any instance x of type Any, x.equals(x) should return true.
  • It is symmetric: for any instances x and y of type Any, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any instances 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)).

Parameters
arg0 - the object to compare against this object for equality.
Returns
true if the receiver object is equivalent to the argument; false otherwise.

Overrides
SequenceTemplate.equals