|
Scala Library
|
|
scala/collection/immutable/List.scala]
sealed abstract
class
List[+A]
extends LinearSeq[A] with Product with GenericTraversableTemplate[A, List] with LinearSeqLike[A, List[A]]a. This class comes with two implementing case
classes scala.Nil and scala.:: that
implement the abstract members isEmpty,
head and tail.| Method Summary | |
override def
|
++
[B >: A, That](that : Iterator[B])(implicit bf : CanBuildFrom[List[A], B, That]) : That
Create a new list which contains all elements of this list
followed by all elements of Iterator `that'
|
override def
|
++
[B >: A, That](that : Traversable[B])(implicit bf : CanBuildFrom[List[A], B, That]) : That
Create a new list which contains all elements of this list
followed by all elements of Traversable `that'
|
def
|
-
[B >: A](x : B) : List[B]
Computes the difference between this list and the given object
x. |
def
|
--
[B >: A](that : List[B]) : List[B]
Computes the difference between this list and the given list
that. |
def
|
:: [B >: A](x : B) : List[B] |
def
|
::: [B >: A](prefix : List[B]) : List[B] |
override def
|
companion
: GenericCompanion[List]
The factory companion object that builds instances of class CC
|
override def
|
drop
(n : Int) : List[A]
Returns the list without its
n first elements.
If this list has less than n elements, the empty list is returned. |
override def
|
dropWhile
(p : (A) => Boolean) : List[A]
Returns the longest suffix of this list whose first element
does not satisfy the predicate
p. |
abstract def
|
head
: A
Returns this first element of the list.
|
abstract def
|
isEmpty
: Boolean
Returns true if the list does not contain any elements.
|
def
|
mapConserve
[B >: A](f : (A) => B) : List[B]
Like xs map f, but returns
xs unchanged if function
f maps all elements to themselves (wrt ==). |
override def
|
reverse
: List[A]
A list consisting of all elements of this list in reverse order.
|
def
|
reverse_:::
[B >: A](prefix : List[B]) : List[B]
Reverse the given prefix and append the current list to that.
This function is equivalent to an application of
reverse
on the prefix followed by a call to :::, but is more
efficient. |
override def
|
slice
(start : Int, end : Int) : List[A]
Returns the list with elements belonging to the given index range.
|
def
|
sort (lt : (A, A) => Boolean) : List[A] |
override def
|
span
(p : (A) => Boolean) : (List[A], List[A])
Returns the longest prefix of the list whose elements all satisfy
the given predicate, and the rest of the list.
|
override def
|
splitAt
(n : Int) : (List[A], List[A])
Split the list at a given point and return the two parts thus
created.
|
override def
|
stringPrefix
: java.lang.String
Defines the prefix of this object's
toString representation. |
abstract def
|
tail
: List[A]
Returns this list without its first element.
|
override def
|
take
(n : Int) : List[A]
Returns the
n first elements of this list, or else the whole
list, if it has less than n elements. |
override def
|
takeRight
(n : Int) : List[A]
Returns the rightmost
n elements from this list. |
override def
|
takeWhile
(p : (A) => Boolean) : List[A]
Returns the longest prefix of this list whose elements satisfy
the predicate
p. |
override def
|
toList
: List[A]
Overrides the method in Iterable for efficiency.
|
override def
|
toStream
: Stream[A]
Returns a stream with all elements in this iterable object.
|
| Methods inherited from Product | |
| productElement (abstract), productArity (abstract), productIterator, productElements, productPrefix |
| Methods inherited from LinearSeqLike | |
| thisCollection, toCollection, length, apply, iterator, foreach, forall, exists, count, find, foldLeft, foldRight, reduceLeft, reduceRight, last, dropRight, sameElements, lengthCompare, isDefinedAt, segmentLength, indexWhere, lastIndexWhere |
| Methods inherited from SeqLike | |
| size, prefixLength, indexWhere, findIndexOf, indexOf, indexOf, lastIndexOf, lastIndexOf, lastIndexWhere, 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 PartialFunction | |
| orElse, andThen |
| Methods inherited from Function1 | |
| compose |
| Methods inherited from IterableLike | |
| elements, toIterable, copyToArray, zip, zipAll, zipWithIndex, canEqual, first, firstOption |
| Methods inherited from GenericTraversableTemplate | |
| newBuilder, genericBuilder, unzip, flatten, transpose |
| Methods inherited from TraversableLike | |
| repr, nonEmpty, hasDefiniteSize, map, flatMap, filter, filterNot, partialMap, remove, partition, groupBy, /:, :\, reduceLeftOption, reduceRightOption, sum, product, min, max, headOption, lastOption, init, copyToBuffer, copyToArray, toArray, toIndexedSeq, toSet, mkString, mkString, mkString, addString, addString, addString, withFilter |
| Methods inherited from AnyRef | |
| getClass, clone, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized |
| Methods inherited from Any | |
| ==, !=, isInstanceOf, asInstanceOf |
| Method Details |
override
def
companion : GenericCompanion[List]
abstract
def
isEmpty : Boolean
true, iff the list is empty.abstract
def
head : A
Add an element x at the beginning of this list.
x - the element to prepend.x added at the beginning.1 :: List(2, 3) = List(2, 3).::(1) = List(1, 2, 3)
Returns a list resulting from the concatenation of the given
list prefix and this list.
prefix - the list to concatenate at the beginning of this list.List(1, 2) ::: List(3, 4) = List(3, 4).:::(List(1, 2)) = List(1, 2, 3, 4)reverse
on the prefix followed by a call to :::, but is more
efficient.prefix - the prefix to reverse and then prependxs unchanged if function
f maps all elements to themselves (wrt ==).override
def
++[B >: A, That](that : Traversable[B])(implicit bf : CanBuildFrom[List[A], B, That]) : That
override
def
++[B >: A, That](that : Iterator[B])(implicit bf : CanBuildFrom[List[A], B, That]) : That
n first elements of this list, or else the whole
list, if it has less than n elements.n - the number of elements to take.n first elements of this list.n first elements.
If this list has less than n elements, the empty list is returned.n - the number of elements to drop.n first elements.start - the start position of the list slice.end - the end position (exclusive) of the list slice.n elements from this list.n - the number of elements to taken of the listn - the position at which to splitn elements, and the other elements.p.p - the test predicate.p.p.p - the test predicate.p.p - the test predicatep, and the rest of the list.override
def
stringPrefix : java.lang.String
toString representation.that.that - the list of elements to remove from this list.that.
def
-[B >: A](x : B) : List[B]
x.x - the object to remove from this list.x.
Sort the list according to the comparison function
lt(e1: a, e2: a) => Boolean,
which should be true iff e1 precedes
e2 in the desired ordering.
!!! todo: move sorting to IterableLike
lt - the comparison functionlt(e1: a, e2: a) => Boolean. List("Steve", "Tom", "John", "Bob")
.sort((e1, e2) => (e1 compareTo e2) < 0) =
List("Bob", "John", "Steve", "Tom")|
Scala Library
|
|