in scala
class List

sealed abstract class List [ a ]
extends java.lang.Object
with Seq
with ScalaObject
A class representing an ordered collection of elements of type a. This class comes with two implementing case classes scala.Nil and scala.:: that implement the abstract members isEmpty, head and tail.
author:
Martin Odersky and others
version:
1.0, 16/07/2003

Constructor Summary
def this



Def Summary
def :: [ a <: b& ] ( x : b& ) : List
Add an element x at the beginning of this list.

Ex:
1 :: [2, 3] = [2, 3].::(1) = [1, 2, 3].

def ::: [ a <: b& ] ( prefix : List ) : List
Returns a list resulting from the concatenation of the given list prefix and this list.

Ex:
[1, 2] ::: [3, 4] = [3, 4].:::([1, 2]) = [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 : Function1 ) : Tuple2
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 : Function1 ) : scala.Int
Count the number of elements in the list which satisfy a predicate.
def diff [ a <: b& ] ( that : List ) : List
Computes the difference between this list and the given list that.
override def drop ( n : scala.Int ) : List
Returns the list without its n first elements.
def dropRight ( n : scala.Int ) : List
Returns the list wihout its rightmost n elements.
def dropWhile ( p : Function1 ) : List
Returns the longest suffix of this list whose first element does not satisfy the predicate p.
def elements : Iterator
Returns the elements in the list as an iterator
override def exists ( p : Function1 ) : scala.Boolean
Tests the existence in this list of an element that satisfies the predicate p.
def filter ( p : Function1 ) : List
Returns all the elements of this list that satisfy the predicate p. The order of the elements is preserved.
override def find ( p : Function1 ) : Option
Find and return the first element of the list satisfying a predicate, if any.
def flatMap [ b& ] ( f : Function1 ) : List
Applies the given function f to each element of this list, then concatenates the results.
override def foldLeft [ b& ] ( z : b& ) ( f : Function2 ) : b&
Combines the elements of this list together using the binary operator op, from left to right, and starting with the value z.
override def foldRight [ b& ] ( z : b& ) ( f : Function2 ) : b&
Combines the elements of this list together using the binary operator op, from rigth to left, and starting with the value z.
override def forall ( p : Function1 ) : scala.Boolean
Tests if the predicate p is satisfied by all elements in this list.
override def foreach ( f : Function1 ) : scala.Unit
Apply the given function f to each element of this list (while respecting the order of the elements).
def head : a
Returns this first element of the list.
def indices : List
Creates a list with all indices in the list. This is equivalent to a call to List.range(0, xs.length).
def init : List
Returns the list without its last element.
def intersect [ a <: b& ] ( that : List ) : List
Computes the intersection between this list and the given list that.
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 : Function1 ) : List
Returns the list resulting from applying the given function f to each element of this list.
def partition ( p : Function1 ) : Tuple2
Partition the list in two sub-lists according to a predicate.
def reduceLeft [ a <: b& ] ( f : Function2 ) : b&

def reduceRight [ a <: b& ] ( f : Function2 ) : b&

def remove ( p : Function1 ) : List
Removes all elements of the list which satisfy the predicate p. This is like filter with the predicate inversed.
def removeDuplicates : List
Removes redundant elements from the list. Uses the method == to decide if two elements are identical.
def reverse : List
Reverses the elements of this list.

Ex:
[1, 2, 3] reverse = [3, 2, 1].

def reverseMap [ b& ] ( f : Function1 ) : List
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_::: [ a <: b& ] ( prefix : List ) : List
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 : Function2 ) : List
Sort the list according to the comparison function <(e1: a, e2: a) => Boolean, which should be true iff e1 is smaller than e2. Note: The current implementation is inefficent for already sorted lists.
def span ( p : Function1 ) : Tuple2
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 ) : Tuple2
Split the list at a given point and return the two parts thus created.
override protected def stringPrefix : java.lang.String

def tail : List
Returns this list without its first element.
override def take ( n : scala.Int ) : List
Returns the n first elements of this list.
def takeRight ( n : scala.Int ) : List
Returns the rightmost n elements from this list.
def takeWhile ( p : Function1 ) : List
Returns the longest prefix of this list whose elements satisfy the predicate p.
def toArray [ a <: b& ] : Array
Converts the list to an Array
override def toList : List
Overrides the method in Iterable for efficiency.
def union [ a <: b& ] ( that : List ) : List
Computes the union of this list and the given list that.
def zip [ b& ] ( that : List ) : List
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& , a <: c& , b <: d& ] ( that : List , thisElem : c& , thatElem : d& ) : List
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.


Constructor Detail
def this

Def Detail
def :: [ a <: b& ]( x : b& ) : List
Add an element x at the beginning of this list.

Ex:
1 :: [2, 3] = [2, 3].::(1) = [1, 2, 3].

param:
x the element to append.
return:
the list with x appended at the beginning.

def ::: [ a <: b& ]( prefix : List ) : List
Returns a list resulting from the concatenation of the given list prefix and this list.

Ex:
[1, 2] ::: [3, 4] = [3, 4].:::([1, 2]) = [1, 2, 3, 4].

param:
prefix the list to concatenate at the beginning of this list.
return:
the concatenation of the two lists.

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.
param:
n index of the element to return
return:
the element at position n in this list.
throws:
java.lang.RuntimeException if the list is too short.

def break ( p : Function1 ) : Tuple2
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.
param:
elem element whose membership has to be tested.
return:
True iff there is an element of this list which is equal (w.r.t. ==) to elem.

def count ( p : Function1 ) : scala.Int
Count the number of elements in the list which satisfy a predicate.
param:
p the predicate for which to count
return:
the number of elements satisfying the predicate p.

def diff [ a <: b& ]( that : List ) : List
Computes the difference between this list and the given list that.
param:
that the list of elements to remove from this list.
return:
this list without the elements of the given list that.

override def drop ( n : scala.Int ) : List
Returns the list without its n first elements.
param:
n the number of elements to drop.
return:
the list without its n first elements.

def dropRight ( n : scala.Int ) : List
Returns the list wihout its rightmost n elements.
param:
n the number of elements to take
return:
the suffix of length n of the list
throws:
java.lang.RuntimeException if the list is too short.

def dropWhile ( p : Function1 ) : List
Returns the longest suffix of this list whose first element does not satisfy the predicate p.
param:
p the test predicate.
return:
the longest suffix of the list whose first element does not satisfy the predicate p.

def elements : Iterator
Returns the elements in the list as an iterator
return:
an iterator on the list elements.

override def exists ( p : Function1 ) : scala.Boolean
Tests the existence in this list of an element that satisfies the predicate p.
param:
p the test predicate.
return:
true iff there exists an element in this list that satisfies the predicate p.

def filter ( p : Function1 ) : List
Returns all the elements of this list that satisfy the predicate p. The order of the elements is preserved.
param:
p the redicate used to filter the list.
return:
the elements of this list satisfying p.

override def find ( p : Function1 ) : Option
Find and return the first element of the list satisfying a predicate, if any.
param:
p the predicate
return:
the first element in the list satisfying p, or None if none exists.

def flatMap [ b& ]( f : Function1 ) : List
Applies the given function f to each element of this list, then concatenates the results.
param:
f the function to apply on each element.
return:
f(a0) ::: ... ::: f(an) if this list is [a0, ..., an].

override def foldLeft [ b& ]( z : b& ) ( f : Function2 ) : b&
Combines the elements of this list together using the binary operator op, from left to right, and starting with the value z.
return:
op(... (op(op(z,a0),a1) ...), an) if the list is [a0, a1, ..., an].

override def foldRight [ b& ]( z : b& ) ( f : Function2 ) : b&
Combines the elements of this list together using the binary operator op, from rigth to left, and starting with the value z.
return:
a0 op (... op (an op z)...) if the list is [a0, a1, ..., an].

override def forall ( p : Function1 ) : scala.Boolean
Tests if the predicate p is satisfied by all elements in this list.
param:
p the test predicate.
return:
True iff all elements of this list satisfy the predicate p.

override def foreach ( f : Function1 ) : scala.Unit
Apply the given function f to each element of this list (while respecting the order of the elements).
param:
f the treatment to apply to each element.

def head : a
Returns this first element of the list.
return:
the first element of this list.
throws:
java.lang.RuntimeException if the list is empty.

def indices : List
Creates a list with all indices in the list. This is equivalent to a call to List.range(0, xs.length).
return:
a list of all indices in the list.

def init : List
Returns the list without its last element.
return:
the list without its last element.
throws:
java.lang.RuntimeException if the list is empty.

def intersect [ a <: b& ]( that : List ) : List
Computes the intersection between this list and the given list that.
param:
that the list to intersect.
return:
the list of elements contained both in this list and in the given list that.

def isEmpty : scala.Boolean
Returns true if the list does not contain any elements.
return:
true, iff the list is empty.

def last : a
Returns the last element of this list.
return:
the last element of the list.
throws:
java.lang.RuntimeException if the list is empty.

def length : scala.Int
Returns the number of elements in the list.
return:
the number of elements in the list.

def map [ b& ]( f : Function1 ) : List
Returns the list resulting from applying the given function f to each element of this list.
param:
f function to apply to each element.
return:
[f(a0), ..., f(an)] if this list is [a0, ..., an].

def partition ( p : Function1 ) : Tuple2
Partition the list in two sub-lists according to a predicate.
param:
p the predicate on which to partition
return:
a pair of lists: the list of all elements which satisfy 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.

def reduceLeft [ a <: b& ]( f : Function2 ) : b&

def reduceRight [ a <: b& ]( f : Function2 ) : b&

def remove ( p : Function1 ) : List
Removes all elements of the list which satisfy the predicate p. This is like filter with the predicate inversed.
param:
p the predicate to use to test elements
return:
the list without all elements which satisfy p

def removeDuplicates : List
Removes redundant elements from the list. Uses the method == to decide if two elements are identical.
return:
the list without doubles.

def reverse : List
Reverses the elements of this list.

Ex:
[1, 2, 3] reverse = [3, 2, 1].

return:
the elements of this list in reverse order.

def reverseMap [ b& ]( f : Function1 ) : List
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.
param:
f the function to apply to each elements.
return:
the reversed list of results.

def reverse_::: [ a <: b& ]( prefix : List ) : List
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).
param:
prefix the prefix to reverse and then prepend
return:
the concatenation of the reversed prefix and the current list.

def sort ( lt : Function2 ) : List
Sort the list according to the comparison function <(e1: a, e2: a) => Boolean, which should be true iff e1 is smaller than e2. Note: The current implementation is inefficent for already sorted lists.
param:
lt the comparison function
return:
a list sorted according to the comparison function <(e1: a, e2: a) => Boolean.

def span ( p : Function1 ) : Tuple2
Returns the longest prefix of the list whose elements all satisfy the given predicate, and the rest of the list.
param:
p the test predicate
return:
a pair consisting of the longest prefix of the list whose elements all satisfy p, and the rest of the list.

def splitAt ( n : scala.Int ) : Tuple2
Split the list at a given point and return the two parts thus created.
param:
n the position at which to split
return:
a pair of lists composed of the first n elements, and the other elements.

override protected def stringPrefix : java.lang.String

def tail : List
Returns this list without its first element.
return:
this list without its first element.
throws:
java.lang.RuntimeException if the list is empty.

override def take ( n : scala.Int ) : List
Returns the n first elements of this list.
param:
n the number of elements to take.
return:
the n first elements of this list.

def takeRight ( n : scala.Int ) : List
Returns the rightmost n elements from this list.
param:
n the number of elements to take
return:
the suffix of length n of the list
throws:
java.lang.RuntimeException if the list is too short.

def takeWhile ( p : Function1 ) : List
Returns the longest prefix of this list whose elements satisfy the predicate p.
param:
p the test predicate.
return:
the longest prefix of this list whose elements satisfy the predicate p.

def toArray [ a <: b& ] : Array
Converts the list to an Array

override def toList : List
Overrides the method in Iterable for efficiency.
return:
the list itself

def union [ a <: b& ]( that : List ) : List
Computes the union of this list and the given list that.
param:
that the list of elements to add to the list.
return:
a list without doubles containing the elements of this list and those of the given list that.

def zip [ b& ]( that : List ) : List
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.
param:
that must have the same length as the self list.
return:
[(a0,b0), ..., (an,bn)] when [a0, ..., an] zip [b0, ..., bn] is invoked.

def zipAll [ b& , a <: c& , b <: d& ]( that : List , thisElem : c& , thatElem : d& ) : List
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.
param:
that may have a different length as the self list.
param:
thisElem is used to fill up the resulting list if the self list is shorter than that
param:
thatElem is used to fill up the resulting list if that is shorter than the self list
return:
[(a0,b0), ..., (an,bn), (elem,bn+1), ..., (elem,bm)] when [a0, ..., an] zip [b0, ..., bm] is invoked where m > n.