Scala Library
|
|
scala/collection/immutable/List.scala
]
sealed abstract
class
List[+A]
extends
LinearSequence[A] with
Product with
TraversableClass[A, List] with
LinearSequenceTemplate[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 : Traversable[B])(implicit bf : BuilderFactory[B, That, List[A]]) : That
Create a new list which contains all elements of this list
followed by all elements of Traversable `that'
|
override def
|
++
[B >: A, That](that : Iterator[B])(implicit bf : BuilderFactory[B, That, List[A]]) : That
Create a new list which contains all elements of this list
followed by all elements of Iterator `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
: Companion[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
|
reverseMap
[B](f : (A) => B) : List[B]
Apply a function to all the elements of the list, and return the
reversed list of results. This is equivalent to a call to
map
followed by a call to reverse , but more efficient.
!!! should we deprecate this? Why have reverseMap, but not filterMap or reverseFilter, say? |
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 traversable object.
|
Methods inherited from Product | |
productElement (abstract), productArity (abstract), productIterator, productElements, productPrefix, canEqual |
Methods inherited from LinearSequenceTemplate | |
length, apply, iterator, foreach, forall, exists, count, find, foldLeft, foldRight, reduceLeft, reduceRight, last, dropRight, sameElements, lengthCompare, isDefinedAt, segmentLength, indexWhere, lastIndexWhere, equals |
Methods inherited from Sequence | |
hashCode |
Methods inherited from SequenceTemplate | |
size, zip, zipAll, zipWithIndex, prefixLength, indexWhere, findIndexOf, indexOf, indexOf, lastIndexOf, lastIndexOf, lastIndexWhere, 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 PartialFunction | |
orElse, andThen |
Methods inherited from Function1 | |
compose |
Methods inherited from IterableTemplate | |
elements, toIterable, first, firstOption, toSeq |
Methods inherited from TraversableClass | |
newBuilder, genericBuilder, unzip, flatten, transpose |
Methods inherited from TraversableTemplate | |
thisCollection, nonEmpty, hasDefiniteSize, map, flatMap, filter, filterMap, filterNot, remove, partition, groupBy, /:, :\, reduceLeftOption, reduceRightOption, headOption, lastOption, init, copyToBuffer, copyToArray, copyToArray, toArray, toSet, mkString, mkString, mkString, addString, addString, addString |
Methods inherited from AnyRef | |
getClass, clone, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized |
Methods inherited from Any | |
==, !=, isInstanceOf, asInstanceOf |
Method Details |
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 prependmap
followed by a call to reverse
, but more efficient.
!!! should we deprecate this? Why have reverseMap, but not filterMap or reverseFilter, say?f -
the function to apply to each elements.xs
unchanged if function
f
maps all elements to themselves (wrt ==).override
def
++[B >: A, That](that : Traversable[B])(implicit
bf : BuilderFactory[B, That, List[A]]) : That
override
def
++[B >: A, That](that : Iterator[B])(implicit
bf : BuilderFactory[B, That, List[A]]) : 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
<(e1: a, e2: a) => Boolean
,
which should be true iff e1
is smaller than
e2
.
!!! todo: move sorting to IterableTemplate
lt -
the comparison function<(e1: a, e2: a) => Boolean
.List("Steve", "Tom", "John", "Bob") .sort((e1, e2) => (e1 compareTo e2) < 0) = List("Bob", "John", "Steve", "Tom")
Scala Library
|
|