13.10 The list type

append($x$)
The append($x$) method appends the object $x$ to a list and returns the new list.

count($x$)
The count($x$) method returns the number of items in a list that equal $x$.

extend($x$)
The extend($x$) method appends the members of a list or vector $x$ to the operand and returns the new list.

filter($f$)
The filter($f$) method takes a pointer to a function of one argument, $f(a)$. It calls the function for every element of the list, and returns a new list of those elements for which $f(a)$ tests true.

index($x$)
The index($x$) method returns the index of the first element of a list that equals $x$, or $-1$ if no elements match.

insert$n,x$)
The insert$n,x$) method inserts the number $x$ into a list at position $n$, and returns the new list.

len()
The len() method returns the number of elements in a list.

map($f$)
The map($f$) method takes a pointer to a function of one argument, $f(a)$. It calls the function for every element of the list, and returns a list of the results.

max()
The max() method returns the highest-valued item in a list.

min()
The min() method returns the lowest-valued item in a list.

pop()
The pop() method returns the last item in a list, and removes it from the list.

reduce($f$)
The reduce($f$) method takes a pointer to a function of two arguments. It first calls $f(a,b)$ on the first two elements of the list, and then continues through the list calling $f(a,b)$ on the result and the next item in the list. The final result is returned.

reverse()
The reverse() method reverses the order of the members of a list, and returns the new list.

sort()
The sort() method sorts the members of a list into ascending order, and returns the new list.

sortOn($f$)
The sortOn($f$) method sorts the members of a list using the user-supplied function $f(a,b)$ to determine the sort order. $f$ should return $1$, $0$ or $-1$ depending whether $a>b$, $a=b$ or $a<b$.

sortOnElement($n$)
The sortOnElement($n$) method sorts a list of lists on the $n$th element of each sublist. If $n$ is negative, it counts from the final item of each list, $n=-1$ being the last item.

vector()
The vector() method returns the elements in a list as a vector.