in scala
class List

abstract sealed class List[+a]()
extends Seq[a]
with ScalaObject
Implementing classes or objects:
class ::[+b](hd: b, tl: List[b])
object Nil

A trait 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

Method Summary
  def ::[b >: a](x: b): List[b]
     Add an element x at the beginning of this list.
  def :::[b >: a](prefix: List[b]): List[b]
     Returns a list resulting from the concatenation of the given list prefix and this list.
  def apply(n: Int): a
     Returns the n-th element of this list.
  def break(p: (a) => Boolean): Tuple2[List[a],List[a]]
     Like span but with the predicate inverted.
  def contains(elem: Any): Boolean
     Tests if the given value elem is a member of this iterable object.
  def count(p: (a) => Boolean): Int
     Count the number of elements in the list which satisfy a predicate.
  def diff[b >: a](that: List[b]): List[b]
     Computes the difference between this list and the given list that.
override def drop(n: Int): List[a]
     Returns the list without its n first elements.
  def dropRight(n: Int): List[a]
     Returns the list wihout its rightmost n elements.
  def dropWhile(p: (a) => Boolean): List[a]
     Returns the longest suffix of this list whose first element does not satisfy the predicate p.
  def elements: Iterator[a]
     Returns the elements in the list as an iterator
override def exists(p: (a) => Boolean): Boolean
     Tests the existence in this list of an element that satisfies the predicate p.
  def filter(p: (a) => Boolean): List[a]
     Returns all the elements of this list that satisfy 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.
  def flatMap[b](f: (a) => List[b]): 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 operator op, 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 operator op, from rigth 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(f: (a) => Unit): 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: List[Int]
     Creates a list with all indices in the list.
  def init: List[a]
     Returns the list without its last element.
  def intersect[b >: a](that: List[b]): List[b]
     Computes the intersection between this list and the given list that.
abstract def isEmpty: Boolean
     Returns true if the list does not contain any elements.
  def last: a
     Returns the last element of this list.
  def length: Int
     Returns the number of elements in the list.
  def map[b](f: (a) => b): List[b]
     Returns the list resulting from applying the given function f to each element of this list.
  def mkString(start: String, sep: String, end: String): String
     Returns a string representation of this list.
  def partition(p: (a) => Boolean): Tuple2[List[a],List[a]]
     Partition the list in two sub-lists according to a predicate.
  def reduceLeft[b >: a](f: (b,b) => b): b
  def reduceRight[b >: a](f: (b,b) => b): b
  def remove(p: (a) => Boolean): List[a]
     Removes all elements of the list which satisfy the predicate p.
  def removeDuplicates: List[a]
     Removes redundant elements from the list.
  def reverse: List[a]
     Reverses the elements of this list.
  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.
  def reverse_:::[b >: a](prefix: List[b]): List[b]
     Reverse the given prefix and append the current list to that.
  def sort(lt: (a,a) => Boolean): 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.
  def span(p: (a) => Boolean): Tuple2[List[a],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: Int): Tuple2[List[a],List[a]]
     Split the list at a given point and return the two parts thus created.
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.
  def takeRight(n: Int): List[a]
     Returns the rightmost n elements from this list.
  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]
     Transform this sequence into a list of all elements.
override def toString(): String
     Customizes the toString method.
  def union[b >: a](that: List[b]): List[b]
     Computes the union of this list and the given list that.
  def zip[b](that: List[b]): List[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[c >: a,b](that: List[b], thisElem: c, thatElem: b): List[Tuple2[c,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.

Methods inherited from java/lang/Object-class
clone, eq, equals, finalize, getClass, hashCode, ne, notify, notifyAll, synchronized, wait, wait, wait

Methods inherited from scala/Any-class
!=, ==, asInstanceOf, isInstanceOf, match

Methods inherited from scala/Iterable-class
/:, :\, concat, sameElements

Methods inherited from scala/ScalaObject-class
getScalaType

Methods inherited from scala/Seq-class
concat, copyToArray, indexOf, isDefinedAt, lastIndexOf, stringPrefix, subseq

Method Detail

isEmpty

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

head

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

tail

  abstract def tail: List[a]
Returns this list without its first element.
Returns:
this list without its first element.
Throws:
java.lang.RuntimeException if the list is empty.

::

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

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

Parameters:
x - the element to append.
Returns:
the list with x appended at the beginning.

:::

  def :::[b >: a](prefix: List[b]): List[b]
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].

Parameters:
prefix - the list to concatenate at the beginning of this list.
Returns:
the concatenation of the two lists.

reverse_:::

  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 more efficient (and tail recursive).
Parameters:
prefix - the prefix to reverse and then prepend
Returns:
the concatenation of the reversed prefix and the current list.

length

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

indices

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

elements

  def elements: Iterator[a]
Returns the elements in the list as an iterator
Returns:
an iterator on the list elements.

toList

  override def toList: List[a]
Transform this sequence into a list of all elements.
Returns:
a list which enumerates all elements of this sequence.

init

  def init: List[a]
Returns the list without its last element.
Returns:
the list without its last element.
Throws:
java.lang.RuntimeException if the list is empty.

last

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

take

  override def take(n: Int): List[a]
Returns the n first elements of this list.
Parameters:
n - the number of elements to take.
Returns:
the n first elements of this list.

drop

  override def drop(n: Int): List[a]
Returns the list without its n first elements.
Parameters:
n - the number of elements to drop.
Returns:
the list without its n first elements.

takeRight

  def takeRight(n: Int): List[a]
Returns the rightmost n elements from this list.
Parameters:
n - the number of elements to take
Returns:
the suffix of length n of the list
Throws:
java.lang.RuntimeException if the list is too short.

dropRight

  def dropRight(n: Int): List[a]
Returns the list wihout its rightmost n elements.
Parameters:
n - the number of elements to take
Returns:
the suffix of length n of the list
Throws:
java.lang.RuntimeException if the list is too short.

splitAt

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

takeWhile

  def takeWhile(p: (a) => Boolean): List[a]
Returns the longest prefix of this list whose elements satisfy the predicate p.
Parameters:
p - the test predicate.
Returns:
the longest prefix of this list whose elements satisfy the predicate p.

dropWhile

  def dropWhile(p: (a) => Boolean): List[a]
Returns the longest suffix of this list whose first element does not satisfy the predicate p.
Parameters:
p - the test predicate.
Returns:
the longest suffix of the list whose first element does not satisfy the predicate p.

span

  def span(p: (a) => Boolean): Tuple2[List[a],List[a]]
Returns the longest prefix of the list whose elements all satisfy the given predicate, and the rest of the list.
Parameters:
p - the test predicate
Returns:
a pair consisting of the longest prefix of the list whose elements all satisfy p, and the rest of the list.

break

  def break(p: (a) => Boolean): Tuple2[List[a],List[a]]
Like span but with the predicate inverted.

apply

  def apply(n: Int): a
Returns the n-th element of this list. The first element (head of the list) is at position 0.
Parameters:
n - index of the element to return
Returns:
the element at position n in this list.
Throws:
java.lang.RuntimeException if the list is too short.

map

  def map[b](f: (a) => b): List[b]
Returns the list resulting from applying the given function f to each element of this list.
Parameters:
f - function to apply to each element.
Returns:
[f(a0), ..., f(an)] if this list is [a0, ..., an].

reverseMap

  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.
Parameters:
f - the function to apply to each elements.
Returns:
the reversed list of results.

foreach

  override def foreach(f: (a) => Unit): Unit
Apply the given function f to each element of this list (while respecting the order of the elements).
Parameters:
f - the treatment to apply to each element.

filter

  def filter(p: (a) => Boolean): List[a]
Returns all the elements of this list that satisfy the predicate p. The order of the elements is preserved.
Parameters:
p - the redicate used to filter the list.
Returns:
the elements of this list satisfying p.

remove

  def remove(p: (a) => Boolean): List[a]
Removes all elements of the list which satisfy the predicate p. This is like filter with the predicate inversed.
Parameters:
p - the predicate to use to test elements
Returns:
the list without all elements which satisfy p

partition

  def partition(p: (a) => Boolean): Tuple2[List[a],List[a]]
Partition the list in two sub-lists according to a predicate.
Parameters:
p - the predicate on which to partition
Returns:
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.

sort

  def sort(lt: (a,a) => Boolean): 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. Note: The current implementation is inefficent for already sorted lists.
Parameters:
lt - the comparison function
Returns:
a list sorted according to the comparison function <(e1: a, e2: a) => Boolean.

count

  def count(p: (a) => Boolean): Int
Count the number of elements in the list which satisfy a predicate.
Parameters:
p - the predicate for which to count
Returns:
the number of elements satisfying the predicate p.

forall

  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.

exists

  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.

contains

  def contains(elem: Any): Boolean
Tests if the given value elem is a member of this iterable object.
Parameters:
elem - element whose membership has to be tested.
Returns:
True iff there is an element of this list which is equal (w.r.t. ==) to elem.

find

  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.

foldLeft

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

foldRight

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

reduceLeft

  def reduceLeft[b >: a](f: (b,b) => b): b

reduceRight

  def reduceRight[b >: a](f: (b,b) => b): b

flatMap

  def flatMap[b](f: (a) => List[b]): List[b]
Applies the given function f to each element of this list, then concatenates the results.
Parameters:
f - the function to apply on each element.
Returns:
f(a0) ::: ... ::: f(an) if this list is [a0, ..., an].

reverse

  def reverse: List[a]
Reverses the elements of this list.

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

Returns:
the elements of this list in reverse order.

mkString

  def mkString(start: String, sep: String, end: String): String
Returns a string representation of this list. The resulting string begins with the string start and is finished by the string end. Inside, the string representations of elements (w.r.t. the method toString()) are separated by the string sep.

Ex:
List(1, 2, 3).mkString("(", "; ", ")") = "(1; 2; 3)"

Parameters:
start - starting string.
sep - separator string.
end - ending string.
Returns:
a string representation of this list.

toString

  override def toString(): String
Customizes the toString method.
Returns:
a string representation of this sequence.

zip

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

zipAll

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

union

  def union[b >: a](that: List[b]): List[b]
Computes the union of this list and the given list that.
Parameters:
that - the list of elements to add to the list.
Returns:
a list without doubles containing the elements of this list and those of the given list that.

diff

  def diff[b >: a](that: List[b]): List[b]
Computes the difference between this list and the given list that.
Parameters:
that - the list of elements to remove from this list.
Returns:
this list without the elements of the given list that.

intersect

  def intersect[b >: a](that: List[b]): List[b]
Computes the intersection between this list and the given list that.
Parameters:
that - the list to intersect.
Returns:
the list of elements contained both in this list and in the given list that.

removeDuplicates

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