List
fn map[A, B](xs: List[A], f: fn(A) -> B fails E(f) uses { R(f) }) -> List[B] fails E(f) uses { R(f) }Applies f to each element.
fn each[A](xs: List[A], f: fn(A) -> () fails E(f) uses { R(f) }) -> () fails E(f) uses { R(f) }Calls f on each element, from the first to the last. Stops at the first failure.
filter
Section titled “filter”fn filter[A](xs: List[A], f: fn(A) -> Bool fails E(f) uses { R(f) }) -> List[A] fails E(f) uses { R(f) }Keeps the order.
fn fold[A, B](xs: List[A], from: B, f: fn(B, A) -> B fails E(f) uses { R(f) }) -> B fails E(f) uses { R(f) }Folds from the front: f(f(f(from, x0), x1), x2).
length
Section titled “length”fn length[A](xs: List[A]) -> IntThe number of elements.
is_empty
Section titled “is_empty”fn is_empty[A](xs: List[A]) -> BoolWhether the list is empty.
fn get[A](xs: List[A], index: Int) -> Option[A]Zero-based. None if out of range or negative.
fn head[A](xs: List[A]) -> Option[A]None if empty.
fn tail[A](xs: List[A]) -> List[A]Empty if empty.
reverse
Section titled “reverse”fn reverse[A](xs: List[A]) -> List[A]The elements in reverse order.
append
Section titled “append”fn append[A](xs: List[A], ys: List[A]) -> List[A]Joins two lists: the elements of xs, then those of ys.
fn join(xs: List[String], sep: String) -> StringJoins the strings with sep in between: ["a", "b"].join(", ") is "a, b".
s.split(sep).join(sep) == s holds.
flatten
Section titled “flatten”fn flatten[A](xss: List[List[A]]) -> List[A]Flattens a list of lists, keeping the order.
partition
Section titled “partition”fn partition[A](xs: List[A], f: fn(A) -> Bool fails E(f) uses { R(f) }) -> (List[A], List[A]) fails E(f) uses { R(f) }Splits into the elements where f is True and those where it is False, both in order.
(evens, odds) = xs.partition(is_even).
fn any[A](xs: List[A], f: fn(A) -> Bool fails E(f) uses { R(f) }) -> Bool fails E(f) uses { R(f) }Stops at the first match. False if empty.
fn all[A](xs: List[A], f: fn(A) -> Bool fails E(f) uses { R(f) }) -> Bool fails E(f) uses { R(f) }Stops at the first False. True if empty.
fn find[A](xs: List[A], f: fn(A) -> Bool fails E(f) uses { R(f) }) -> Option[A] fails E(f) uses { R(f) }The first element where f is True.
fn range(from: Int, to: Int) -> List[Int]The integers from from up to but excluding to, ascending. Empty if to <= from.
fn zip[A, B](xs: List[A], ys: List[B]) -> List[(A, B)]Pairs elements at the same position. As long as the shorter list.
fn take[A](xs: List[A], n: Int) -> List[A]The first n elements, or all of them if there are fewer. Empty if n is not positive.
fn drop[A](xs: List[A], n: Int) -> List[A]The elements after the first n. All of them if n is not positive.
fn last[A](xs: List[A]) -> Option[A]The last element.
flat_map
Section titled “flat_map”fn flat_map[A, B](xs: List[A], f: fn(A) -> List[B] fails E(f) uses { R(f) }) -> List[B] fails E(f) uses { R(f) }f on each element, with the lists it returns joined in order.
filter_map
Section titled “filter_map”fn filter_map[A, B](xs: List[A], f: fn(A) -> Option[B] fails E(f) uses { R(f) }) -> List[B] fails E(f) uses { R(f) }The values of f that are Some, in order.
find_index
Section titled “find_index”fn find_index[A](xs: List[A], f: fn(A) -> Bool fails E(f) uses { R(f) }) -> Option[Int] fails E(f) uses { R(f) }The index of the first element for which f is True.
enumerate
Section titled “enumerate”fn enumerate[A](xs: List[A]) -> List[(Int, A)]Each element paired with its index, from 0.
fn unzip[A, B](xys: List[(A, B)]) -> (List[A], List[B])The first and second of each pair, as two lists.
sort_by
Section titled “sort_by”fn sort_by[A](xs: List[A], f: fn(A, A) -> Ordering fails E(f) uses { R(f) }) -> List[A] fails E(f) uses { R(f) }Sorted by f, a merge sort. Stable: elements that f finds Equal keep their order.
fn sort[A: Ord](xs: List[A]) -> List[A]Sorted in the order of Ord ([trait.builtin]). Stable.