Enum list::List [-]  [+] [src]

pub enum List<A> {
    Nil,
    Cons(A, Box<List<A>>),
}

Rust implementation of OCaml's 'a list.

Variants

Nil
Cons

Methods

impl<A> List<A>

fn length(&self) -> int

Return the length (number of elements) of the given list.

impl<A: Clone> List<A>

fn hd(&self) -> Option<A>

Return the first element of the given list. Return None if the list is empty.

fn tl(&self) -> Option<List<A>>

Return the given list without its first element. Return None if the list is empty.

fn nth(&self, i: uint) -> Option<A>

Return the n-th element of the given list. The first element (head of the list) is at position 0. Return None if the list is too short.

fn rev(&self) -> List<A>

List reversal.

fn append(&self, ys: &List<A>) -> List<A>

Catenate two lists.

fn rev_append(&self, ys: &List<A>) -> List<A>

l1.rev_append(l2) reverses l1 and concatenates it to l2. This is equivalent to l1.rev().append(l2).

fn concat<A: Clone>(xss: List<&List<A>>) -> List<A>

Concatenate a list of lists. The elements of the argument are all concatenated together (in the same order) to give the result.

fn flatten<A: Clone>(xss: List<&List<A>>) -> List<A>

Same as concat.

impl<'a, A> List<A>

fn iter(&'a self, f: |&'a A|)

list![a1, ..., an].iter(f) applies f in turn to a1, ..., an. It is equivalent to {f(a1); f(a2); ...; f(an);}.

fn iteri(&'a self, f: |int, &'a A|)

Same as iter, but the function is applied to the index of the elements as first argument (counting from 0), and the element itself as second argument.

fn map<B>(&'a self, f: |&'a A| -> B) -> List<B>

list![a1, ..., an].map(f) applies function f to a1, ..., an, and builds the list list![f(a1), ..., f(an)] with the results returned by f.

fn mapi<B>(&'a self, f: |int, &'a A| -> B) -> List<B>

Same as map, but the function is applied to the index of the elements as first argument (counting from 0), and the element itself as second argument.

fn rev_map<B>(&'a self, f: |&'a A| -> B) -> List<B>

l.rev_map(f) gives the same results as l.rev().map(f).

fn fold_left<B>(&'a self, f: |B, &'a A| -> B, a: B) -> B

list![b1, ..., bn].fold_left(f, a) is f (... (f ( f a b1) b2) ... ) bn.

fn fold_right<B>(&'a self, f: |&'a A, B| -> B, a: B) -> B

list![a1, ..., an].fold_right(f, b) is f a1 (f a2 (... (f an b) ...)).

fn iter2<'b, B>(&'a self, f: |&'a A, &'b B|, ys: &'b List<B>) -> Option<()>

list![a1, ..., an].iter2(f, list![b1, ..., bn]) calls in turn f(a1, b1), ..., f(an, bn). Return None if the two lists have different lengths.

fn map2<'b, B, C>(&'a self, f: |&'a A, &'b B| -> C, ys: &'b List<B>) -> Option<List<C>>

list![a1, ..., an].map2(f, list![b1, ..., bn]) is list![f(a1, b1), ..., f(an, bn)]. Return None if the two lists have different lengths.

fn rev_map2<'b, B, C>(&'a self, f: |&'a A, &'b B| -> C, ys: &'b List<B>) -> Option<List<C>>

l1.rev_map2(f, l2) gives the same result as l1.map2(f, l2).rev().

fn fold_left2<'b, B, C>(&'a self, f: |C, &'a A, &'b B| -> C, a: C, ys: &'b List<B>) -> Option<C>

list![a1, ..., an].fold_left2(f, a, list![b1, ..., bn]) is f (... (f (f a a1 b1) a2 b2) ...) an bn. Return None if the two lists have different length.

fn fold_right2<'b, B, C>(&'a self, f: |&'a A, &'b B, C| -> C, ys: &'b List<B>, a: C) -> Option<C>

list![a1, ..., an].fold_right2(f, a, list![b1, ..., bn]) is f a1 b1 (f a2 b2 (... (f an bn a) ...)). Return None if the two lists have different length.

fn for_all(&'a self, p: |&'a A| -> bool) -> bool

list![a1, ..., an].for_all(p) checks if all elements of the list satisfy the predicate p. That is, it returns (p(a1)) && (p(a2)) && ... && (p(an))

fn exists(&'a self, p: |&'a A| -> bool) -> bool

list![a1, ..., an].for_all(p) checks if at least one element of the list satisfies the predicate p. That is, it returns (p(a1)) || (p(a2)) || ... || (p(an))

fn for_all2<'b, B>(&'a self, p: |&'a A, &'b B| -> bool, ys: &'b List<B>) -> Option<bool>

Same as List::for_all, but for a two-argument predicate. Return None if the two lists have different lengths.

fn exists2<'b, B>(&'a self, p: |&'a A, &'b B| -> bool, ys: &'b List<B>) -> Option<bool>

Same as List::exists, but for a two-argument predicate. Return None if the two lists have different lengths.

impl<'a, A: Eq> List<A>

fn mem(&'a self, y: &A) -> bool

l.mem(a) is true if and only if a is equal to an element of l.

impl<A: Clone> List<A>

fn find(&self, p: |&A| -> bool) -> Option<A>

l.find(p) returns the first element of the list l that satisfies the predicate p. Return None if there is no value that satisfies p in the list l.

fn filter(&self, p: |&A| -> bool) -> List<A>

l.filter(p) returns all the elements of the list l that satisfy the predicate p. The order of the elements in the input list is preserved.

fn find_all(&self, p: |&A| -> bool) -> List<A>

find_all is another name for filter.

fn partition(&self, p: |&A| -> bool) -> (List<A>, List<A>)

l.partition(p) returns a pair of lists (l1, l2) where l1 is the list of all the elements of l that satisfy the predicate p, and l2 is the list of all elements of l that do not satisfy p. The order of the elements in the input list is preserved.

impl<A: Eq, B: Clone> List<(A, B)>

fn assoc(&self, x: A) -> Option<B>

l.assoc(a) returns the value associated with key x in the list of pairs l. That is, list![..., (x, y), ...].assoc(x) == y if (x, y) is the leftmost binding of a in list l. Return None if there is no value associated with x in the list l.

impl<A: Eq, B> List<(A, B)>

fn mem_assoc(&self, x: A) -> bool

Same as assoc, but simple return true if a binding exists, and false if no bindings exist for the given key.

impl<A: Eq + Clone, B: Clone> List<(A, B)>

fn remove_assoc(&self, x: A) -> List<(A, B)>

l.remove_assoc(x) returns the list of pairs l without the first pair with key x, if any.

impl<A: Clone, B: Clone> List<(A, B)>

fn split(&self) -> (List<A>, List<B>)

Transform a list of pairs into a pair of lists: list![(a1, b1), ..., (an, bn)].split() is (list![a1, ..., an], list![b1, ..., bn]).

impl<A: Clone> List<A>

fn combine<B: Clone>(&self, ys: &List<B>) -> Option<List<(A, B)>>

Transform a pair of lists into a list of pairs: list![a1, ..., an].combine(list![b1, ..., bn]) is list![(a1,b2), ..., (an,bn)]. Return None if the two lists have different lengths.

fn sort(&self, cmp: |&A, &A| -> int) -> List<A>

Sort a list in increasing order according to a comparison function. The comparison function must return 0 if the arguments compare as equal, a positive integer if the first is greater, and a negative integer if the first is smaller. The resulting list is sorted in increasing order.

fn stable_sort(&self, cmp: |&A, &A| -> int) -> List<A>

Same as sort but the sorting algorithm is guaranteed to be stable (i.e. elements that compare equal are kept in their original order).

fn fast_sort(&self, cmp: |&A, &A| -> int) -> List<A>

Same as sort or stable_sort, whichever is faster on typical input.

fn sort_uniq(&self, cmp: |&A, &A| -> int) -> List<A>

Same as sort, but also remove duplicates.

fn merge(&self, cmp: |&A, &A| -> int, ys: &List<A>) -> List<A>

Merge two lists: Assuming that l1 and l2 are sorted according to the comparison function cmp, l1.merge(cmp, l2) will return a sorted list containing all the elemnts of l1 and l2. If several elements compare equal, the elements of l1 will be before the elements of l2.

impl<A> List<A>

fn into_hd(self) -> Option<A>

Non-borrowing implementation of hd.

fn into_tl(self) -> Option<List<A>>

Non-borrowing implementation of tl.

fn into_nth(self, i: uint) -> Option<A>

Non-borrowing implementation of nth.

fn appended(self, ys: List<A>) -> List<A>

Non-borrowing implementation of append.

fn rev_appended(self, ys: List<A>) -> List<A>

Non-borrowing implementation of rev_append.

fn concated<A>(xss: List<List<A>>) -> List<A>

Non-borrowing implementation of concat.

fn flattened<A>(xss: List<List<A>>) -> List<A>

Non-borrowing implementation of flatten.

fn itered(self, f: |A|)

Non-borrowing implementation of iter.

fn iteried(self, f: |int, A|)

Non-borrowing implementation of iteri.

fn mapped<B>(self, f: |A| -> B) -> List<B>

Non-borrowing implementation of map.

fn mapied<B>(self, f: |int, A| -> B) -> List<B>

Non-borrowing implementation of mapi.

fn rev_mapped<B>(self, f: |A| -> B) -> List<B>

Non-borrowing implementation of rev_map.

fn folded_left<B>(self, f: |B, A| -> B, a: B) -> B

Non-borrowing implementation of fold_left.

fn folded_right<B>(self, f: |A, B| -> B, a: B) -> B

Non-borrowing implementation of fold_right.

fn itered2<B>(self, f: |A, B|, ys: List<B>) -> Option<()>

Non-borrowing implementation of iter2.

fn mapped2<B, C>(self, f: |A, B| -> C, ys: List<B>) -> Option<List<C>>

Non-borrowing implementation of map2.

fn rev_mapped2<B, C>(self, f: |A, B| -> C, ys: List<B>) -> Option<List<C>>

Non-borrowing implementation of rev_map2.

fn folded_left2<B, C>(self, f: |C, A, B| -> C, a: C, ys: List<B>) -> Option<C>

Non-borrowing implementation of fold_left2.

fn folded_right2<B, C>(self, f: |A, B, C| -> C, ys: List<B>, a: C) -> Option<C>

Non-borrowing implementation of fold_right2.

fn for_alled(self, p: |A| -> bool) -> bool

Non-borrowing implementation of for_all.

fn into_exists(self, p: |A| -> bool) -> bool

Non-borrowing implementation of exists.

fn for_alled2<B>(self, p: |A, B| -> bool, ys: List<B>) -> Option<bool>

Non-borrowing implementation of for_all2.

fn into_exists2<B>(self, p: |A, B| -> bool, ys: List<B>) -> Option<bool>

Non-borrowing implementation of exists2.

impl<A: Eq> List<A>

fn memed(self, y: A) -> bool

Non-borrowing implementation of mem.

impl<A> List<A>

fn found(self, p: |&A| -> bool) -> Option<A>

Non-borrowing implementation of find.

fn filtered(self, p: |&A| -> bool) -> List<A>

Non-borrowing implementation of filter.

fn found_all(self, p: |&A| -> bool) -> List<A>

Non-borrowing implementation of find_all.

fn partitioned(self, p: |&A| -> bool) -> (List<A>, List<A>)

Non-borrowing implementation of partition.

impl<A: Eq, B> List<(A, B)>

fn assoced(self, x: A) -> Option<B>

Non-borrowing implementation of assoc.

fn mem_assoced(self, x: A) -> bool

Non-borrowing implementation of mem_assoc.

fn remove_assoced(self, x: A) -> List<(A, B)>

Non-borrowing implementation of remove_assoc.

impl<A, B> List<(A, B)>

fn splitted(self) -> (List<A>, List<B>)

Non-borrowing implementation of split.

impl<A> List<A>

fn combined<B>(self, ys: List<B>) -> Option<List<(A, B)>>

Non-borrowing implementation of combine.

fn sorted(self, cmp: |&A, &A| -> int) -> List<A>

Non-borrowing implementation of sort.

fn stable_sorted(self, cmp: |&A, &A| -> int) -> List<A>

Non-borrowing implementation of stable_sort.

fn fast_sorted(self, cmp: |&A, &A| -> int) -> List<A>

Non-borrowing implementation of fast_sort.

fn sorted_uniq(self, cmp: |&A, &A| -> int) -> List<A>

Non-borrowing implementation of sort_uniq.

fn merged(self, cmp: |&A, &A| -> int, ys: List<A>) -> List<A>

Non-borrowing implementation of merge.

impl<'a, A> List<A>

fn to_iter(&'a self) -> RefItems<'a, A>

impl<A> List<A>

fn into_iter(self) -> MoveItems<A>

Trait Implementations

impl<A> FromIterator<A> for List<A>

fn from_iter<T: Iterator<A>>(iterator: T) -> List<A>

impl<A: Show> Show for List<A>

fn fmt(&self, f: &mut Formatter) -> Result

let nil: List<int> = Nil;
assert_eq!(format!("{}", nil),             "[]");
assert_eq!(format!("{}", list![1i]),       "[1]");
assert_eq!(format!("{}", list![1i, 2]),    "[1, 2]");
assert_eq!(format!("{}", list![1i, 2, 3]), "[1, 2, 3]");

Derived Implementations

impl<A: Eq> Eq for List<A>

fn assert_receiver_is_total_eq(&self)

impl<A: PartialEq> PartialEq for List<A>

fn eq(&self, __arg_0: &List<A>) -> bool

fn ne(&self, __arg_0: &List<A>) -> bool

impl<A: Clone> Clone for List<A>

fn clone(&self) -> List<A>

fn clone_from(&mut self, source: &Self)