in scala
object List

object List
extends Object
with ScalaObject

This object provides methods for creating specialized lists, and for transforming special kinds of lists (e.g. lists of lists).
Author:
Martin Odersky and others
Version:
1.0, 15/07/2003

Method Summary
final def apply[A](xs: A*): List[A]
     Create a list with given elements.
final def exists2[a,b](xs: List[a], ys: List[b])(f: (a,b) => Boolean): Boolean
     Tests whether the given predicate p holds for some corresponding elements of the argument lists.
final def flatten[a](l: List[List[a]]): List[a]
     Concatenate all the elements of a given list of lists.
final def forall2[a,b](xs: List[a], ys: List[b])(f: (a,b) => Boolean): Boolean
     Tests whether the given predicate p holds for all corresponding elements of the argument lists.
final def fromArray[a](arr: Array[a]): List[a]
     Converts an array into a list.
final def fromArray[a](arr: Array[a], start: Int, len: Int): List[a]
     Converts a range of an array into a list.
final def fromIterator[a](it: Iterator[a]): List[a]
     Converts an iterator to a list
final def fromString(str: String, separator: Char): List[String]
     Parses a string which contains substrings separated by a separator character and returns a list of all substrings.
final def fromString(str: String): List[Char]
     Returns the given string as a list of characters.
final def list2ordered[a](view: (a) => Ordered[a])(x: List[a]): Ordered[List[a]]
     Lists with ordered elements are ordered
final def make[a](n: Int, elem: a): List[a]
     Create a list containing several copies of an element.
final def map2[a,b,c](xs: List[a], ys: List[b])(f: (a,b) => c): List[c]
     Returns the list resulting from applying the given function f to corresponding elements of the argument lists.
final def map3[a,b,c,d](xs: List[a], ys: List[b], zs: List[c])(f: (a,b,c) => d): List[d]
     Returns the list resulting from applying the given function f to corresponding elements of the argument lists.
final def mapConserve[a<:Object](xs: List[a])(f: (a) => a): List[a]
     Like xs map f, but returns xs unchanged if function `f' maps all elements to themselves
final def range(from: Int, end: Int): List[Int]
     Create a sorted list of all integers in a range.
final def range(from: Int, end: Int, step: Int): List[Int]
     Create a sorted list of all integers in a range.
final def range(from: Int, end: Int, step: (Int) => Int): List[Int]
     Create a sorted list of all integers in a range.
final def tabulate[a](n: Int, maker: (Int) => a): List[a]
     Create a list by applying a function to successive integers.
final def toString(xs: List[Char]): String
     Returns the given list of characters as a string.
  def toString(): String
final def transpose[a](xss: List[List[a]]): List[List[a]]
     Transposes a list of lists.
final def unzip[a,b](l: List[Tuple2[a,b]]): Tuple2[List[a],List[b]]
     Transforms a list of pair into a pair of lists.
final def view[a](view: (a) => Ordered[a])(x: List[a]): Ordered[List[a]]

Method Detail

apply

  final def apply[A](xs: A*): List[A]
Create a list with given elements.
Parameters:
xs - the elements to put in the list
Returns:
the list containing elements xs.

range

  final def range(from: Int, end: Int): List[Int]
Create a sorted list of all integers in a range.
Parameters:
from - the start value of the list
end - the end value of the list
Returns:
the sorted list of all integers in range [from;end).

range

  final def range(from: Int, end: Int, step: Int): List[Int]
Create a sorted list of all integers in a range.
Parameters:
from - the start value of the list
end - the end value of the list
step - the increment value of the list
Returns:
the sorted list of all integers in range [from;end).

range

  final def range(from: Int, end: Int, step: (Int) => Int): List[Int]
Create a sorted list of all integers in a range.
Parameters:
from - the start value of the list
end - the end value of the list
step - the increment function of the list
Returns:
the sorted list of all integers in range [from;end).

make

  final def make[a](n: Int, elem: a): List[a]
Create a list containing several copies of an element.
Parameters:
n - the length of the resulting list
elem - the element composing the resulting list
Returns:
a list composed of n elements all equal to elem

tabulate

  final def tabulate[a](n: Int, maker: (Int) => a): List[a]
Create a list by applying a function to successive integers.
Parameters:
n - the length of the resulting list
maker - the procedure which, given an integer n, returns the nth element of the resulting list, where n is in [0;n).
Returns:
the list obtained by applying the maker function to successive integers from 0 to n (exclusive).

flatten

  final def flatten[a](l: List[List[a]]): List[a]
Concatenate all the elements of a given list of lists.
Parameters:
l - the list of lists that are to be concatenated
Returns:
the concatenation of all the lists

unzip

  final def unzip[a,b](l: List[Tuple2[a,b]]): Tuple2[List[a],List[b]]
Transforms a list of pair into a pair of lists.
Parameters:
l - the list of pairs to unzip
Returns:
a pair of lists: the first list in the pair contains the list

fromIterator

  final def fromIterator[a](it: Iterator[a]): List[a]
Converts an iterator to a list
Parameters:
it - the iterator to convert
Returns:
a list that contains the elements returned by successive calls to it.next

fromArray

  final def fromArray[a](arr: Array[a]): List[a]
Converts an array into a list.
Parameters:
arr - the array to convert
Returns:
a list that contains the same elements than arr in the same order

fromArray

  final def fromArray[a](arr: Array[a], start: Int, len: Int): List[a]
Converts a range of an array into a list.
Parameters:
arr - the array to convert
start - the first index to consider
len - the lenght of the range to convert
Returns:
a list that contains the same elements than arr in the same order

fromString

  final def fromString(str: String, separator: Char): List[String]
Parses a string which contains substrings separated by a separator character and returns a list of all substrings.
Parameters:
str - the string to parse
separator - the separator character
Returns:
the list of substrings

fromString

  final def fromString(str: String): List[Char]
Returns the given string as a list of characters.
Parameters:
str - the string to convert.
Returns:
the string as a list of characters.

toString

  final def toString(xs: List[Char]): String
Returns the given list of characters as a string.
Parameters:
xs - the list to convert.
Returns:
the list in form of a string.

toString

  def toString(): String

map2

  final def map2[a,b,c](xs: List[a], ys: List[b])(f: (a,b) => c): List[c]
Returns the list resulting from applying the given function f to corresponding elements of the argument lists.
Parameters:
f - function to apply to each pair of elements.
Returns:
[f(a0,b0), ..., f(an,bn)] if the lists are [a0, ..., ak], [b0, ..., bl] and n = min(k,l)

mapConserve

  final def mapConserve[a<:Object](xs: List[a])(f: (a) => a): List[a]
Like xs map f, but returns xs unchanged if function `f' maps all elements to themselves

map3

  final def map3[a,b,c,d](xs: List[a], ys: List[b], zs: List[c])(f: (a,b,c) => d): List[d]
Returns the list resulting from applying the given function f to corresponding elements of the argument lists.
Parameters:
f - function to apply to each pair of elements.
Returns:
[f(a0,b0,c0), ..., f(an,bn,cn)] if the lists are [a0, ..., ak], [b0, ..., bl], [c0, ..., cm] and n = min(k,l,m)

forall2

  final def forall2[a,b](xs: List[a], ys: List[b])(f: (a,b) => Boolean): Boolean
Tests whether the given predicate p holds for all corresponding elements of the argument lists.
Parameters:
p - function to apply to each pair of elements.
Returns:
n == 0 || (p(a0,b0) && ... && p(an,bn))] if the lists are [a0, ..., ak], [b0, ..., bl] and m = min(k,l)

exists2

  final def exists2[a,b](xs: List[a], ys: List[b])(f: (a,b) => Boolean): Boolean
Tests whether the given predicate p holds for some corresponding elements of the argument lists.
Parameters:
p - function to apply to each pair of elements.
Returns:
n != 0 && (p(a0,b0) || ... || p(an,bn))] if the lists are [a0, ..., ak], [b0, ..., bl] and m = min(k,l)

transpose

  final def transpose[a](xss: List[List[a]]): List[List[a]]
Transposes a list of lists. pre: All element lists have the same length.

list2ordered

  final def list2ordered[a](view: (a) => Ordered[a])(x: List[a]): Ordered[List[a]]
Lists with ordered elements are ordered

view

  final def view[a](view: (a) => Ordered[a])(x: List[a]): Ordered[List[a]]