Enum im::list::List
[−]
[src]
pub enum List<A> { // some variants omitted }
A list of elements of type A.
Methods
impl<A> List<A>
[src]
fn empty() -> List<A>
Construct an empty list.
fn singleton(v: A) -> List<A>
Construct a list with a single element.
fn null(&self) -> bool
Test whether a list is empty.
Time: O(1)
fn cons(&self, car: A) -> List<A>
Construct a list with a new value prepended to the front of the current list.
Time: O(1)
fn head<'a>(&'a self) -> Option<&'a A>
Get the first element of a list.
If the list is empty, None
is returned.
Time: O(1)
fn tail(&self) -> Option<List<A>>
Get the tail of a list.
The tail means all elements in the list after the
first item (the head). If the list only has one
element, the result is an empty list. If the list is
empty, the result is None
.
Time: O(1)
fn uncons<'a>(&'a self) -> Option<(&'a A, List<A>)>
Get the head and the tail of a list.
This function performs both the head
function and
the tail
function in one go, returning a tuple
of the head and the tail, or None
if the list is
empty.
Examples
This can be useful when pattern matching your way through a list:
fn walk_through_list<A>(list: &List<A>) where A: Debug { match list.uncons() { None => (), Some((ref head, ref tail)) => { print!("{:?}", head); walk_through_list(tail) } } }
Time: O(1)
fn uncons2<'a>(&'a self) -> Option<(&'a A, &'a A, List<A>)>
fn length(&self) -> usize
Get the length of a list.
This operation is instant, because cons cells store the length of the list they're the head of.
Time: O(1)
Examples
assert_eq!(5, list![1, 2, 3, 4, 5].length());
impl List<i32>
[src]
fn range(from: i32, to: i32) -> List<i32>
Construct a list of numbers between from
and to
inclusive.
Examples
assert_eq!( List::range(1, 5), list![1, 2, 3, 4, 5] );
impl<A> List<A> where
A: Clone + Ord,
[src]
A: Clone + Ord,
fn insert(&self, item: &A) -> List<A>
Insert an item into a sorted list.
Constructs a new list with the new item inserted before the
first item in the list which is larger than the new item,
as determined by the Ord
trait.
Time: O(n)
Examples
assert_eq!( list![2, 4, 6].insert(&5).insert(&1).insert(&3), list![1, 2, 3, 4, 5, 6] );
fn sort(&self) -> List<A>
Sort a list.
Time: O(n log n)
Examples
assert_eq!( list![2, 8, 1, 6, 3, 7, 5, 4].sort(), List::range(1, 8) );
impl<A> List<A> where
A: Clone,
[src]
A: Clone,
fn from_slice(slice: &[A]) -> List<A>
Construct a list from a slice of items.
Time: O(n)
fn append(&self, right: &List<A>) -> List<A>
Append the list right
to the end of the current list.
Time: O(n)
Examples
assert_eq!( list![1, 2, 3].append(&list![7, 8, 9]), list![1, 2, 3, 7, 8, 9] );
fn reverse(&self) -> List<A>
Construct a list which is the reverse of the current list.
Time: O(n)
Examples
assert_eq!( list![1, 2, 3, 4, 5].reverse(), list![5, 4, 3, 2, 1] );
fn iter(&self) -> ListIter<A>
Get an iterator over a list.
fn sort_by(&self, cmp: &Fn(&A, &A) -> Ordering) -> List<A>
Sort a list using a comparator function.
Time: O(n log n)
Trait Implementations
impl<A> Clone for List<A>
[src]
fn clone(&self) -> Self
Clone a list.
Cons cells use Arc
behind the scenes, so this is no more
expensive than cloning an Arc
reference.
Time: O(1)
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl<A> Default for List<A>
[src]
fn default() -> Self
Default
for lists is the empty list.
impl<A> IntoIterator for List<A> where
A: Clone,
[src]
A: Clone,
type Item = A
The type of the elements being iterated over.
type IntoIter = ListIter<A>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
Creates an iterator from a value. Read more
impl<A> FromIterator<A> for List<A> where
A: Clone,
[src]
A: Clone,
fn from_iter<T>(iter: T) -> Self where
T: IntoIterator<Item = A>,
T: IntoIterator<Item = A>,
Creates a value from an iterator. Read more
impl<'a, A> FromIterator<&'a A> for List<A> where
A: 'a + Clone,
[src]
A: 'a + Clone,
fn from_iter<T>(iter: T) -> Self where
T: IntoIterator<Item = &'a A>,
T: IntoIterator<Item = &'a A>,
Creates a value from an iterator. Read more
impl<'a, A> From<&'a [A]> for List<A> where
A: Clone,
[src]
A: Clone,
impl<A> PartialEq for List<A> where
A: PartialEq + Clone,
[src]
A: PartialEq + Clone,
fn eq(&self, other: &List<A>) -> bool
Test if two lists are equal.
This could potentially be an expensive operation, as we need to walk both lists to test for equality. We can very quickly determine equality if both lists are references to the same cons cell (they're equal) or if the lists have different lengths (can't be equal). Otherwise, we walk the lists to compare values.
Time: O(n)
fn ne(&self, other: &List<A>) -> bool
This method tests for !=
.
impl<A> Eq for List<A> where
A: Eq + Clone,
[src]
A: Eq + Clone,
impl<A> Hash for List<A> where
A: Clone + Hash,
[src]
A: Clone + Hash,
fn hash<H>(&self, state: &mut H) where
H: Hasher,
H: Hasher,
Feeds this value into the state given, updating the hasher as necessary.
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0
H: Hasher,
Feeds a slice of this type into the state provided.
impl<A> AsRef<List<A>> for List<A>
[src]
impl<A> Debug for List<A> where
A: Debug,
[src]
A: Debug,