List2 is a list of all elements Elem in
List1 for which Pred(Elem) returns
true.

flatlength(DeepList) -> integer() >= 0

Types:

DeepList = [term() | DeepList]

Equivalent to length(flatten(DeepList)), but more
efficient.

flatmap(Fun, List1) -> List2

Types:

Fun = fun((A) -> [B])

List1 = [A]

List2 = [B]

A = B = term()

Takes a function from As to lists of Bs, and a
list of As (List1) and produces a list of
Bs by applying the function to every element in
List1 and appending the resulting lists.

That is, flatmap behaves as if it had been defined as
follows:

flatmap(Fun, List1) ->
append(map(Fun, List1)).

Example:

> lists:flatmap(fun(X)->[X,X] end, [a,b,c]).
[a,a,b,b,c,c]

flatten(DeepList) -> List

Types:

DeepList = [term() | DeepList]

List = [term()]

Returns a flattened version of DeepList.

flatten(DeepList, Tail) -> List

Types:

DeepList = [term() | DeepList]

Tail = List = [term()]

Returns a flattened version of DeepList with the tail
Tail appended.

foldl(Fun, Acc0, List) -> Acc1

Types:

Fun = fun((Elem :: T, AccIn) -> AccOut)

Acc0 = Acc1 = AccIn = AccOut = term()

List = [T]

T = term()

Calls Fun(Elem, AccIn) on successive elements A
of List, starting with AccIn == Acc0.
Fun/2 must return a new accumulator which is passed to
the next call. The function returns the final value of
the accumulator. Acc0 is returned if the list is empty.
For example:

Returns true if there is a tuple in TupleList
whose Nth element compares equal to Key, otherwise
false.

keymerge(N, TupleList1, TupleList2) -> TupleList3

Types:

N = integer() >= 1

1..tuple_size(Tuple)

TupleList1 = [T1]

TupleList2 = [T2]

TupleList3 = [(T1 | T2)]

T1 = T2 = Tuple

Tuple = tuple()

Returns the sorted list formed by merging TupleList1
and TupleList2. The merge is performed on
the Nth element of each tuple. Both TupleList1 and
TupleList2 must be key-sorted prior to evaluating this
function. When two tuples compare equal, the tuple from
TupleList1 is picked before the tuple from
TupleList2.

keyreplace(Key, N, TupleList1, NewTuple) -> TupleList2

Types:

Key = term()

N = integer() >= 1

1..tuple_size(Tuple)

TupleList1 = TupleList2 = [Tuple]

NewTuple = Tuple

Tuple = tuple()

Returns a copy of TupleList1 where the first
occurrence of a T tuple whose Nth element
compares equal to Key is replaced with
NewTuple, if there is such a tuple T.

Searches the list of tuples TupleList for a
tuple whose Nth element compares equal to Key.
Returns {value, Tuple} if such a tuple is found,
otherwise false.

Note

This function is retained for backward compatibility.
The function lists:keyfind/3 (introduced in R13A)
is in most cases more convenient.

keysort(N, TupleList1) -> TupleList2

Types:

N = integer() >= 1

1..tuple_size(Tuple)

TupleList1 = TupleList2 = [Tuple]

Tuple = tuple()

Returns a list containing the sorted elements of the list
TupleList1. Sorting is performed on the Nth
element of the tuples. The sort is stable.

keystore(Key, N, TupleList1, NewTuple) -> TupleList2

Types:

Key = term()

N = integer() >= 1

1..tuple_size(Tuple)

TupleList1 = [Tuple]

TupleList2 = [Tuple, ...]

NewTuple = Tuple

Tuple = tuple()

Returns a copy of TupleList1 where the first
occurrence of a tuple T whose Nth element
compares equal to Key is replaced with
NewTuple, if there is such a tuple T. If there
is no such tuple T a copy of TupleList1 where
[NewTuple] has been appended to the end is
returned.

keytake(Key, N, TupleList1) -> {value, Tuple, TupleList2} | false

Types:

Key = term()

N = integer() >= 1

1..tuple_size(Tuple)

TupleList1 = TupleList2 = [tuple()]

Tuple = tuple()

Searches the list of tuples TupleList1 for a tuple
whose Nth element compares equal to Key.
Returns {value, Tuple, TupleList2} if such a tuple is
found, otherwise false. TupleList2 is a copy
of TupleList1 where the first occurrence of
Tuple has been removed.

last(List) -> Last

Types:

List = [T, ...]

Last = T

T = term()

Returns the last element in List.

map(Fun, List1) -> List2

Types:

Fun = fun((A) -> B)

List1 = [A]

List2 = [B]

A = B = term()

Takes a function from As to Bs, and a list of
As and produces a list of Bs by applying
the function to every element in the list. This function is
used to obtain the return values. The evaluation order is
implementation dependent.

mapfoldl(Fun, Acc0, List1) -> {List2, Acc1}

Types:

Fun = fun((A, AccIn) -> {B, AccOut})

Acc0 = Acc1 = AccIn = AccOut = term()

List1 = [A]

List2 = [B]

A = B = term()

mapfoldl combines the operations of map/2 and
foldl/3 into one pass. An example, summing
the elements in a list and double them at the same time:

Returns the sorted list formed by merging all the sub-lists
of ListOfLists. All sub-lists must be sorted prior to
evaluating this function. When two elements compare equal,
the element from the sub-list with the lowest position in
ListOfLists is picked before the other element.

merge(List1, List2) -> List3

Types:

List1 = [X]

List2 = [Y]

List3 = [(X | Y)]

X = Y = term()

Returns the sorted list formed by merging List1 and
List2. Both List1 and List2 must be
sorted prior to evaluating this function. When two elements
compare equal, the element from List1 is picked
before the element from List2.

merge(Fun, List1, List2) -> List3

Types:

Fun = fun((A, B) -> boolean())

List1 = [A]

List2 = [B]

List3 = [(A | B)]

A = B = term()

Returns the sorted list formed by merging List1 and
List2. Both List1 and List2 must be
sorted according to the ordering functionFun prior to evaluating this function. Fun(A,
B) should return true if A compares less
than or equal to B in the ordering, false
otherwise. When two elements compare equal, the element from
List1 is picked before the element from
List2.

merge3(List1, List2, List3) -> List4

Types:

List1 = [X]

List2 = [Y]

List3 = [Z]

List4 = [(X | Y | Z)]

X = Y = Z = term()

Returns the sorted list formed by merging List1,
List2 and List3. All of List1,
List2 and List3 must be sorted prior to
evaluating this function. When two elements compare equal,
the element from List1, if there is such an element,
is picked before the other element, otherwise the element
from List2 is picked before the element from
List3.

min(List) -> Min

Types:

List = [T, ...]

Min = T

T = term()

Returns the first element of List that compares
less than or equal to all other elements of
List.

nth(N, List) -> Elem

Types:

N = integer() >= 1

1..length(List)

List = [T, ...]

Elem = T

T = term()

Returns the Nth element of List. For example:

> lists:nth(3, [a, b, c, d, e]).
c

nthtail(N, List) -> Tail

Types:

N = integer() >= 0

0..length(List)

List = [T, ...]

Tail = [T]

T = term()

Returns the Nth tail of List, that is, the sublist of
List starting at N+1 and continuing up to
the end of the list. For example:

Returns a list with the elements in List1
in reverse order, with the tail Tail appended. For
example:

> lists:reverse([1, 2, 3, 4], [a, b, c]).
[4,3,2,1,a,b,c]

seq(From, To) -> Seqseq(From, To, Incr) -> Seq

Types:

From = To = Incr = integer()

Seq = [integer()]

Returns a sequence of integers which starts with From
and contains the successive results of adding Incr to
the previous element, until To has been reached or
passed (in the latter case, To is not an element of
the sequence). Incr defaults to 1.

Failure: If To<From-Incr and Incr
is positive, or if To>From-Incr and Incr is
negative, or if Incr==0 and From/=To.

Returns a new list List3 which is a copy of
List1, subjected to the following procedure: for each
element in List2, its first occurrence in List1
is deleted. For example:

> lists:subtract("123212", "212").
"312".

lists:subtract(A, B) is equivalent to A -- B.

Warning

The complexity of lists:subtract(A, B) is proportional
to length(A)*length(B), meaning that it will be very slow if
both A and B are long lists.
(Using ordered lists and
ordsets:subtract/2
is a much better choice if both lists are long.)

suffix(List1, List2) -> boolean()

Types:

List1 = List2 = [T]

T = term()

Returns true if List1 is a suffix of
List2, otherwise false.

sum(List) -> number()

Types:

List = [number()]

Returns the sum of the elements in List.

takewhile(Pred, List1) -> List2

Types:

Pred = fun((Elem :: T) -> boolean())

List1 = List2 = [T]

T = term()

Takes elements Elem from List1 while
Pred(Elem) returns true, that is,
the function returns the longest prefix of the list for which
all elements satisfy the predicate.

ukeymerge(N, TupleList1, TupleList2) -> TupleList3

Types:

N = integer() >= 1

1..tuple_size(Tuple)

TupleList1 = [T1]

TupleList2 = [T2]

TupleList3 = [(T1 | T2)]

T1 = T2 = Tuple

Tuple = tuple()

Returns the sorted list formed by merging TupleList1
and TupleList2. The merge is performed on the
Nth element of each tuple. Both TupleList1 and
TupleList2 must be key-sorted without duplicates
prior to evaluating this function. When two tuples compare
equal, the tuple from TupleList1 is picked and the
one from TupleList2 deleted.

ukeysort(N, TupleList1) -> TupleList2

Types:

N = integer() >= 1

1..tuple_size(Tuple)

TupleList1 = TupleList2 = [Tuple]

Tuple = tuple()

Returns a list containing the sorted elements of the list
TupleList1 where all but the first tuple of the
tuples comparing equal have been deleted. Sorting is
performed on the Nth element of the tuples.

umerge(ListOfLists) -> List1

Types:

ListOfLists = [List]

List = List1 = [T]

T = term()

Returns the sorted list formed by merging all the sub-lists
of ListOfLists. All sub-lists must be sorted and
contain no duplicates prior to evaluating this function.
When two elements compare equal, the element from the
sub-list with the lowest position in ListOfLists is
picked and the other one deleted.

umerge(List1, List2) -> List3

Types:

List1 = [X]

List2 = [Y]

List3 = [(X | Y)]

X = Y = term()

Returns the sorted list formed by merging List1 and
List2. Both List1 and List2 must be
sorted and contain no duplicates prior to evaluating this
function. When two elements compare equal, the element from
List1 is picked and the one from List2
deleted.

umerge(Fun, List1, List2) -> List3

Types:

Fun = fun((A, B) -> boolean())

List1 = [A]

List2 = [B]

List3 = [(A | B)]

A = B = term()

Returns the sorted list formed by merging List1 and
List2. Both List1 and List2 must be
sorted according to the ordering functionFun and contain no duplicates prior to evaluating
this function. Fun(A, B) should return true if
A compares less than or equal to B in the
ordering, false otherwise. When two elements compare
equal, the element from
List1 is picked and the one from List2
deleted.

umerge3(List1, List2, List3) -> List4

Types:

List1 = [X]

List2 = [Y]

List3 = [Z]

List4 = [(X | Y | Z)]

X = Y = Z = term()

Returns the sorted list formed by merging List1,
List2 and List3. All of List1,
List2 and List3 must be sorted and contain no
duplicates prior to evaluating this function. When two
elements compare equal, the element from List1 is
picked if there is such an element, otherwise the element
from List2 is picked, and the other one deleted.

unzip(List1) -> {List2, List3}

Types:

List1 = [{A, B}]

List2 = [A]

List3 = [B]

A = B = term()

"Unzips" a list of two-tuples into two lists, where the first
list contains the first element of each tuple, and the second
list contains the second element of each tuple.

unzip3(List1) -> {List2, List3, List4}

Types:

List1 = [{A, B, C}]

List2 = [A]

List3 = [B]

List4 = [C]

A = B = C = term()

"Unzips" a list of three-tuples into three lists, where
the first list contains the first element of each tuple,
the second list contains the second element of each tuple, and
the third list contains the third element of each tuple.

usort(List1) -> List2

Types:

List1 = List2 = [T]

T = term()

Returns a list containing the sorted elements of
List1 where all but the first element of the elements
comparing equal have been deleted.

usort(Fun, List1) -> List2

Types:

Fun = fun((T, T) -> boolean())

List1 = List2 = [T]

T = term()

Returns a list which contains the sorted elements of
List1 where all but the first element of the elements
comparing equal according to the ordering functionFun have been deleted. Fun(A, B) should return
true if A compares less than or equal to
B in the ordering, false otherwise.

zip(List1, List2) -> List3

Types:

List1 = [A]

List2 = [B]

List3 = [{A, B}]

A = B = term()

"Zips" two lists of equal length into one list of two-tuples,
where the first element of each tuple is taken from the first
list and the second element is taken from corresponding
element in the second list.

zip3(List1, List2, List3) -> List4

Types:

List1 = [A]

List2 = [B]

List3 = [C]

List4 = [{A, B, C}]

A = B = C = term()

"Zips" three lists of equal length into one list of
three-tuples, where the first element of each tuple is taken
from the first list, the second element is taken from
corresponding element in the second list, and the third
element is taken from the corresponding element in the third
list.

zipwith(Combine, List1, List2) -> List3

Types:

Combine = fun((X, Y) -> T)

List1 = [X]

List2 = [Y]

List3 = [T]

X = Y = T = term()

Combine the elements of two lists of equal length into one
list. For each pair X, Y of list elements from the two
lists, the element in the result list will be
Combine(X, Y).