scala.collection.immutable

object List

[source: scala/collection/immutable/List.scala]

object List
extends SeqFactory[List]
This object provides methods for creating specialized lists, and for transforming special kinds of lists (e.g. lists of lists).
Author
Martin Odersky
Version
2.8
Since
2.8
Method Summary
override def apply [A](xs : A*) : List[A]
Creates an iterable of type CC with specified elements.
implicit def canBuildFrom [A] : CanBuildFrom[List, A, List[A]]
override def empty [A] : List[A]
The empty iterable of type CC.
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.
def flatten [A](xss : List[List[A]]) : List[A]
Concatenate all the elements of a given list of lists.
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.
def fromArray [A](arr : Array[A], start : Int, len : Int) : List[A]
Converts a range of an array into a list.
def fromArray [A](arr : Array[A]) : List[A]
Converts an array into a list.
def fromIterator [A](it : Iterator[A]) : List[A]
Converts an iterator to a list.
def fromString (str : java.lang.String) : List[Char]
Returns the given string as a list of characters.
def lefts [A, B](es : Iterable[Either[A, B]]) : List[A]
Returns the Left values in the given Iterable of Eithers.
def make [A](n : Int, elem : A) : List[A]
Create a list containing several copies of an element.
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.
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.
def mapConserve [A <: AnyRef](xs : List[A])(f : (A) => A) : List[A]
Like xs map f, but returns xs unchanged if function f maps all elements to themselves.
def newBuilder [A] : Builder[A, List[A]]
def range (start : Int, end : Int, step : (Int) => Int) : List[Int]
Create a sorted list with element values vn+1 = step(vn) where v0 = start and elements are in the range between start (inclusive) and end (exclusive)
def rights [A, B](es : Iterable[Either[A, B]]) : List[B]
Returns the Right values in the givenIterable of Eithers.
def separate [A, B](es : Iterable[Either[A, B]]) : (List[A], List[B])
Transforms an Iterable of Eithers into a pair of lists.
def toString (xs : List[Char]) : java.lang.String
Returns the given list of characters as a string.
def transpose [A](xss : List[List[A]]) : List[List[A]]
Transposes a list of lists. pre: All element lists have the same length.
def unzip [A, B](xs : List[(A, B)]) : (List[A], List[B])
Transforms a list of pairs into a pair of lists.
def unzip [A, B](xs : Iterable[(A, B)]) : (List[A], List[B])
Transforms an iterable of pairs into a pair of lists.
Methods inherited from SeqFactory
unapplySeq
Methods inherited from TraversableFactory
concat, fill, fill, fill, fill, fill, tabulate, tabulate, tabulate, tabulate, tabulate, range, range, iterate
Methods inherited from AnyRef
getClass, hashCode, equals, clone, toString, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized
Methods inherited from Any
==, !=, isInstanceOf, asInstanceOf
Method Details
implicit def canBuildFrom[A] : CanBuildFrom[List, A, List[A]]

def newBuilder[A] : Builder[A, List[A]]

override def empty[A] : List[A]
The empty iterable of type CC.

override def apply[A](xs : A*) : List[A]
Creates an iterable of type CC with specified elements.

@deprecated("use `iterate' instead")

def range(start : Int, end : Int, step : (Int) => Int) : List[Int]
Create a sorted list with element values vn+1 = step(vn) where v0 = start and elements are in the range between start (inclusive) and end (exclusive)
Parameters
start - the start value of the list
end - the end value of the list
step - the increment function of the list, which given vn, computes vn+1. Must be monotonically increasing or decreasing.
Returns
the sorted list of all integers in range [start;end).

@deprecated("use `fill' instead")

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

@deprecated("use `xss.flatten' instead")

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

@deprecated("use `xs.unzip' instead")

def unzip[A, B](xs : List[(A, B)]) : (List[A], List[B])
Transforms a list of pairs into a pair of lists.
Parameters
xs - the list of pairs to unzip
Returns
a pair of lists.

@deprecated("use `xs.unzip' instead")

def unzip[A, B](xs : Iterable[(A, B)]) : (List[A], List[B])
Transforms an iterable of pairs into a pair of lists.
Parameters
xs - the iterable of pairs to unzip
Returns
a pair of lists.

@deprecated("use `Either.lefts' instead")

def lefts[A, B](es : Iterable[Either[A, B]]) : List[A]
Returns the Left values in the given Iterable of Eithers.

@deprecated("use `Either.rights' instead")

def rights[A, B](es : Iterable[Either[A, B]]) : List[B]
Returns the Right values in the givenIterable of Eithers.

@deprecated("use `Either.separate' instead")

def separate[A, B](es : Iterable[Either[A, B]]) : (List[A], List[B])
Transforms an Iterable of Eithers into a pair of lists.
Parameters
xs - the iterable of Eithers to separate
Returns
a pair of lists.

@deprecated("use `it.toList' instead")

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

@deprecated("use `array.toList' instead")

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

@deprecated("use `array.view(start, end).toList' instead")

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

@deprecated("use `str.toList' instead")

def fromString(str : java.lang.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.

@deprecated("use `xs.mkString' instead")

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

@deprecated("use `xs.mapConserve(f)' instead")

def mapConserve[A <: AnyRef](xs : List[A])(f : (A) => A) : List[A]
Like xs map f, but returns xs unchanged if function f maps all elements to themselves.

@deprecated("use `(xs, ys).map(f)' instead")

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)

@deprecated("use `(xs, ys, zs).map(f)' instead")

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)

@deprecated("use `(xs, ys).forall(f)' instead")

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
(p(a0,b0) && ... && p(an,bn))] if the lists are [a0, ..., ak]; [b0, ..., bl] and n = min(k,l)

@deprecated("use `(xs, ys).exists(f)' instead")

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 n = min(k,l)

@deprecated("use `xss.transpose' instead")

def transpose[A](xss : List[List[A]]) : List[List[A]]
Transposes a list of lists. pre: All element lists have the same length.
Parameters
xss - the list of lists
Returns
the transposed list of lists