|
Scala 2.3.1
|
sealed abstract
class
List
[a]
extends
java.lang.Object
with
scala.Seq[a]
with
scala.ScalaObject
a
. This class comes with two implementing case
classes scala.Nil
and scala.::
that
implement the abstract members isEmpty
,
head
and tail
.Constructor Summary | |
def
this
|
Def Summary | |
def
::
[b >: a]
(x: b)
: scala.List[b]
Add an element 1 :: List(2, 3) = List(2, 3).::(1) = List(1, 2, 3) |
|
def
:::
[b >: a]
(prefix: scala.List[b])
: scala.List[b]
Returns a list resulting from the concatenation of the given
list List(1, 2) ::: List(3, 4) = List(3, 4).:::(List(1, 2)) = List(1, 2, 3, 4) |
|
def
apply
(n: scala.Int)
: a
Returns the n -th element of this list. The first element
(head of the list) is at position 0.
|
|
def
break
(p: (a) => scala.Boolean)
: scala.Tuple2[scala.List[a], scala.List[a]]
Like span but with the predicate inverted.
|
|
def
contains
(elem: scala.Any)
: scala.Boolean
Tests if the given value elem is a member of this
iterable object.
|
|
def
count
(p: (a) => scala.Boolean)
: scala.Int
Count the number of elements in the list which satisfy a predicate. |
|
def
diff
[b >: a]
(that: scala.List[b])
: scala.List[b]
Computes the difference between this list and the given list that .
|
|
override
|
def
drop
(n: scala.Int)
: scala.List[a]
Returns the list without its n first elements.
|
def
dropRight
(n: scala.Int)
: scala.List[a]
Returns the list wihout its rightmost n elements.
|
|
def
dropWhile
(p: (a) => scala.Boolean)
: scala.List[a]
Returns the longest suffix of this list whose first element does not satisfy the predicate p .
|
|
def
elements
: scala.Iterator[a]
Returns the elements in the list as an iterator |
|
override
|
def
exists
(p: (a) => scala.Boolean)
: scala.Boolean
Tests the existence in this list of an element that satisfies the predicate p .
|
def
filter
(p: (a) => scala.Boolean)
: scala.List[a]
Returns all the elements of this list that satisfy the predicate p . The order of the elements is preserved.
|
|
override
|
def
find
(p: (a) => scala.Boolean)
: scala.Option[a]
Find and return the first element of the list satisfying a predicate, if any. |
def
flatMap
[b]
(f: (a) => scala.List[b])
: scala.List[b]
Applies the given function f to each element of
this list, then concatenates the results.
|
|
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 rigth to left, and starting with
the value z .
|
override
|
def
forall
(p: (a) => scala.Boolean)
: scala.Boolean
Tests if the predicate p is satisfied by all elements
in this list.
|
override
|
def
foreach
(f: (a) => scala.Unit)
: scala.Unit
Apply the given function f to each element of this list
(while respecting the order of the elements).
|
abstract
|
def
head
: a
Returns this first element of the list. |
def
indices
: scala.List[scala.Int]
Creates a list with all indices in the list. This is equivalent to a call to List.range(0, xs.length) .
|
|
def
init
: scala.List[a]
Returns the list without its last element. |
|
def
intersect
[b >: a]
(that: scala.List[b])
: scala.List[b]
Computes the intersection between this list and the given list that .
|
|
abstract override
|
def
isEmpty
: scala.Boolean
Returns true if the list does not contain any elements. |
def
last
: a
Returns the last element of this list. |
|
def
length
: scala.Int
Returns the number of elements in the list. |
|
def
map
[b]
(f: (a) => b)
: scala.List[b]
Returns the list resulting from applying the given function f to each
element of this list.
|
|
def
partition
(p: (a) => scala.Boolean)
: scala.Tuple2[scala.List[a], scala.List[a]]
Partition the list in two sub-lists according to a predicate. |
|
def
reduceLeft
[b >: a]
(f: (b, b) => b)
: b
Example: val xs = List(1, 2, 3, 4) 0 :: xs reduceLeft ((x:int, y:int) => x + y) = 10 //sum 1 :: xs reduceLeft ((x:int, y:int) => x * y) = 24 //prod |
|
def
reduceRight
[b >: a]
(f: (b, b) => b)
: b
|
|
def
remove
(p: (a) => scala.Boolean)
: scala.List[a]
Removes all elements of the list which satisfy the predicate p . This is like filter with the
predicate inversed.
|
|
def
removeDuplicates
: scala.List[a]
Removes redundant elements from the list. Uses the method ==
to decide if two elements are identical.
|
|
def
reverse
: scala.List[a]
Reverses the elements of this list. Example: List(1, 2, 3) reverse = List(3, 2, 1) |
|
def
reverseMap
[b]
(f: (a) => b)
: scala.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.
|
|
def
reverse_:::
[b >: a]
(prefix: scala.List[b])
: scala.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 more
efficient (and tail recursive).
|
|
def
sort
(lt: (a, a) => scala.Boolean)
: scala.List[a]
Sort the list according to the comparison function
List("Steve", "Tom", "John", "Bob") .sort((e1, e2) => (e1 compareTo e2) < 0) = List("Bob", "John", "Steve", "Tom") Note: The current implementation is inefficent for already sorted lists. |
|
def
span
(p: (a) => scala.Boolean)
: scala.Tuple2[scala.List[a], scala.List[a]]
Returns the longest prefix of the list whose elements all satisfy the given predicate, and the rest of the list. |
|
def
splitAt
(n: scala.Int)
: scala.Tuple2[scala.List[a], scala.List[a]]
Split the list at a given point and return the two parts thus created. |
|
override protected
|
def
stringPrefix
: java.lang.String
|
abstract
|
def
tail
: scala.List[a]
Returns this list without its first element. |
override
|
def
take
(n: scala.Int)
: scala.List[a]
Returns the n first elements of this list.
|
def
takeRight
(n: scala.Int)
: scala.List[a]
Returns the rightmost n elements from this list.
|
|
def
takeWhile
(p: (a) => scala.Boolean)
: scala.List[a]
Returns the longest prefix of this list whose elements satisfy the predicate p .
|
|
override
|
def
toList
: scala.List[a]
Overrides the method in Iterable for efficiency. |
def
union
[b >: a]
(that: scala.List[b])
: scala.List[b]
Computes the union of this list and the given list that .
|
|
def
zip
[b]
(that: scala.List[b])
: scala.List[scala.Tuple2[a, b]]
Returns a list formed from this list and the specified list that by associating each element of the former with
the element at the same position in the latter.
|
|
def
zipAll
[b, c >: a, d >: b]
(that: scala.List[b], thisElem: c, thatElem: d)
: scala.List[scala.Tuple2[c, d]]
Returns a list formed from this list and the specified list that by associating each element of the former with
the element at the same position in the latter.
|
|
def
zipWithIndex
: scala.List[scala.Tuple2[a, scala.Int]]
Returns a list that pairs each element of this list with its index, counting from 0. |
Def inherited from scala.Seq[a] | |
concat , copyToArray, drop, isDefinedAt, isEmpty, lastIndexOf, length, mkString, stringPrefix, subseq, take, toArray, toString |
Constructor Detail |
Def Detail |
def
::
[b >: a](x: b): scala.List[b]
Add an element x
at the beginning of this list.
Example:
1 :: List(2, 3) = List(2, 3).::(1) = List(1, 2, 3)
x -
the element to append.
x
appended at the beginning.
def
:::
[b >: a](prefix: scala.List[b]): scala.List[b]
Returns a list resulting from the concatenation of the given
list prefix
and this list. Example:
List(1, 2) ::: List(3, 4) = List(3, 4).:::(List(1, 2)) = List(1, 2, 3, 4)
prefix -
the list to concatenate at the beginning of this list.
n
-th element of this list. The first element
(head of the list) is at position 0.n -
index of the element to return
n
in this list.
Predef.NoSuchElementException -
if the list is too short.
def
break
(p: (a) => scala.Boolean): scala.Tuple2[scala.List[a], scala.List[a]]
span
but with the predicate inverted.
def
contains
(elem: scala.Any): scala.Boolean
elem
is a member of this
iterable object.elem -
element whose membership has to be tested.
true
iff there is an element of this list which is equal (w.r.t. ==
) to elem
.
def
count
(p: (a) => scala.Boolean): scala.Int
p -
the predicate for which to count
p
.
def
diff
[b >: a](that: scala.List[b]): scala.List[b]
that
.that -
the list of elements to remove from this list.
that
.
override
def
drop
(n: scala.Int): scala.List[a]
n
first elements.n -
the number of elements to drop.
n
first elements.
def
dropRight
(n: scala.Int): scala.List[a]
n
elements.n -
the number of elements to take
n
of the list
def
dropWhile
(p: (a) => scala.Boolean): scala.List[a]
p
.p -
the test predicate.
p
.
def
elements
: scala.Iterator[a]
override
def
exists
(p: (a) => scala.Boolean): scala.Boolean
p
.p -
the test predicate.
true
iff there exists an element in this list that satisfies the predicate p
.
def
filter
(p: (a) => scala.Boolean): scala.List[a]
p
. The order of the elements is preserved.p -
the redicate used to filter the list.
p
.
override
def
find
(p: (a) => scala.Boolean): scala.Option[a]
p -
the predicate
p
, or None
if none exists.
def
flatMap
[b](f: (a) => scala.List[b]): scala.List[b]
f
to each element of
this list, then concatenates the results.f -
the function to apply on each element.
f(a0) ::: ... ::: f(an)
if this list is [a0, ..., an]
.
f
, from left to right, and starting with
the value z
.f(... (f(f(z, a0), a1) ...), an)
if the list is
[a0, a1, ..., an]
.
f
, from rigth to left, and starting with
the value z
.f(a0, f(a1, f(..., f(an, z)...)))
if the list is [a0, a1, ..., an]
.
override
def
forall
(p: (a) => scala.Boolean): scala.Boolean
p
is satisfied by all elements
in this list.p -
the test predicate.
true
iff all elements of this list satisfy the predicate p
.
override
def
foreach
(f: (a) => scala.Unit): scala.Unit
f
to each element of this list
(while respecting the order of the elements).f -
the treatment to apply to each element.
abstract
def
head
: a
Predef.NoSuchElementException -
if the list is empty.
def
indices
: scala.List[scala.Int]
List.range(0, xs.length)
.
def
init
: scala.List[a]
Predef.UnsupportedOperationException -
if the list is empty.
def
intersect
[b >: a](that: scala.List[b]): scala.List[b]
that
.that -
the list to intersect.
that
.
abstract override
def
isEmpty
: scala.Boolean
true
, iff the list is empty.
def
last
: a
Predef.UnsupportedOperationException -
if the list is empty.
def
length
: scala.Int
def
map
[b](f: (a) => b): scala.List[b]
f
to each
element of this list.f -
function to apply to each element.
[f(a0), ..., f(an)]
if this list is [a0, ..., an]
.
def
partition
(p: (a) => scala.Boolean): scala.Tuple2[scala.List[a], scala.List[a]]
p -
the predicate on which to partition
p
and the list of all elements which do not.
The relative order of the elements in the sub-lists is the
same as in the original list.
Example:
val xs = List(1, 2, 3, 4) 0 :: xs reduceLeft ((x:int, y:int) => x + y) = 10 //sum 1 :: xs reduceLeft ((x:int, y:int) => x * y) = 24 //prod
Predef.UnsupportedOperationException -
if the list is empty.
Predef.UnsupportedOperationException -
if the list is empty.
def
remove
(p: (a) => scala.Boolean): scala.List[a]
p
. This is like filter
with the
predicate inversed.p -
the predicate to use to test elements
p
def
removeDuplicates
: scala.List[a]
==
to decide if two elements are identical.
def
reverse
: scala.List[a]
Reverses the elements of this list. Example:
List(1, 2, 3) reverse = List(3, 2, 1)
def
reverseMap
[b](f: (a) => b): scala.List[b]
map
followed by a call to reverse
, but more efficient.f -
the function to apply to each elements.
def
reverse_:::
[b >: a](prefix: scala.List[b]): scala.List[b]
reverse
on the prefix followed by a call to :::
, but more
efficient (and tail recursive).prefix -
the prefix to reverse and then prepend
def
sort
(lt: (a, a) => scala.Boolean): scala.List[a]
Sort the list according to the comparison function
<(e1: a, e2: a) => Boolean
,
which should be true iff e1
is smaller than
e2
. Example:
List("Steve", "Tom", "John", "Bob") .sort((e1, e2) => (e1 compareTo e2) < 0) = List("Bob", "John", "Steve", "Tom")
Note: The current implementation is inefficent for already sorted lists.
lt -
the comparison function
<(e1: a, e2: a) => Boolean
.
def
span
(p: (a) => scala.Boolean): scala.Tuple2[scala.List[a], scala.List[a]]
p -
the test predicate
p
, and the rest of the list.
def
splitAt
(n: scala.Int): scala.Tuple2[scala.List[a], scala.List[a]]
n -
the position at which to split
n
elements, and the other elements.
override protected
def
stringPrefix
: java.lang.String
abstract
def
tail
: scala.List[a]
Predef.NoSuchElementException -
if the list is empty.
override
def
take
(n: scala.Int): scala.List[a]
n
first elements of this list.n -
the number of elements to take.
n
first elements of this list.
def
takeRight
(n: scala.Int): scala.List[a]
n
elements from this list.n -
the number of elements to take
n
of the list
def
takeWhile
(p: (a) => scala.Boolean): scala.List[a]
p
.p -
the test predicate.
p
.
override
def
toList
: scala.List[a]
def
union
[b >: a](that: scala.List[b]): scala.List[b]
that
.that -
the list of elements to add to the list.
that
.
def
zip
[b](that: scala.List[b]): scala.List[scala.Tuple2[a, b]]
that
by associating each element of the former with
the element at the same position in the latter.that -
list that
must have the same length as the self list.
[(a0,b0), ..., (an,bn)]
when
[a0, ..., an]
zip [b0, ..., bn]
is invoked.
def
zipAll
[b, c >: a, d >: b](that: scala.List[b], thisElem: c, thatElem: d): scala.List[scala.Tuple2[c, d]]
that
by associating each element of the former with
the element at the same position in the latter.that -
list that
may have a different length as the self list.
thisElem -
element thisElem
is used to fill up the resulting list if the self list is shorter than
that
thatElem -
element thatElem
is used to fill up the resulting list if that
is shorter than
the self list
[(a0,b0), ..., (an,bn), (elem,bn+1),
..., (elem,bm)]
when [a0, ..., an] zip
[b0, ..., bm]
is
invoked where m > n
.
def
zipWithIndex
: scala.List[scala.Tuple2[a, scala.Int]]
start -
the index of the first element
(a0,0), (a0,1)...
where ai
are the elements from
this iterator.