[][src]Struct functional_list::List

pub struct List<T> { /* fields omitted */ }

A singly linked list. Implemented using functional algorithms, with no mutation.

Implementations

impl<T> List<T>[src]

pub fn single(v: T) -> Self[src]

Returns a list consisting of a single element

pub const fn nil() -> Self[src]

Returns an empty list

pub fn head(&self) -> Option<&T>[src]

Returns the first element in the list, or if it is empty, returns None

pub fn tail(&self) -> Option<List<T>>[src]

Returns every element in the list except for the first. If the list has <= 1 elements, returns None.

pub fn tail_ref(&self) -> Option<List<&T>>[src]

Returns every element in the list except for the first, as a list of references.

pub fn is_empty(&self) -> bool[src]

Returns true if the list is empty

pub fn len(&self) -> usize[src]

Returns the number of elements in the list

pub fn take(&self, n: usize) -> List<&T>[src]

Returns the first n elements of the list.

pub fn take_while(&self, f: impl FnMut(&T) -> bool) -> List<&T>[src]

Returns the first continuous list of elements that match the condition.

pub fn cons(head: T, tail: Self) -> Self[src]

Returns a new list with head as its first element, and tail as the rest of the list.

pub fn prepend(&self, value: T) -> Self[src]

Equivalent to List::cons(value, (*self).clone())

pub fn for_each<'s>(&'s self, f: impl FnMut(&'s T))[src]

Iterate through the elements of the list

pub fn iter(&self) -> ListIter<'_, T>

Notable traits for ListIter<'list, T>

impl<'list, T> Iterator for ListIter<'list, T> type Item = &'list T;
[src]

Returns an iterator through the elements of the list.

pub fn ref_list(&self) -> List<&T>[src]

Returns a list of references to this list's elements.

pub fn fold<'s, R>(&'s self, initial: R, f: impl FnMut(R, &'s T) -> R) -> R[src]

pub fn reduce<'s>(
    &'s self,
    f: impl FnMut(Option<&'s T>, &'s T) -> Option<&'s T>
) -> Option<&'s T>
[src]

pub fn rev(&self) -> List<&T>[src]

Returns a list of references to this list's elements in reverse order

pub fn append<'a>(&'a self, other: &'a Self) -> List<&'a T>[src]

Append the other list to the end of this list, returning a list of references to both lists' elements.

pub fn map<R>(&self, f: impl Fn(&T) -> R) -> List<R>[src]

Build a new list by applying the passed function to each of the list's elements.

pub fn zip<'a, U>(&'a self, other: &'a List<U>) -> List<(&'a T, &'a U)>[src]

Zip two lists together, forming a list of key-value pairs.

impl<T: Clone> List<T>[src]

pub fn reversed(&self) -> Self[src]

Returns a reversed clone of this list. Equivalent to self.rev().cloned().

impl<'v, T: Clone> List<&'v T>[src]

pub fn cloned(self) -> List<T>[src]

Clones the elements of the list from the references.

impl<T> List<List<T>>[src]

pub fn join(&self) -> List<&T>[src]

Concatenate the inner lists to form a single list.

impl<K, V> List<(K, V)> where
    K: Eq
[src]

pub fn get<Q: ?Sized>(&self, key: &Q) -> Option<&V> where
    K: Borrow<Q>,
    Q: Eq
[src]

Get the element that matches the key, if it exists. Searches the elements in order.

pub fn insert(&self, key: K, value: V) -> Self[src]

Equivalent to self.prepend((key, value))

Trait Implementations

impl<T> Clone for List<T>[src]

impl<T: Debug> Debug for List<T>[src]

impl<T> Default for List<T>[src]

impl<T: Eq + PartialEq> Eq for List<T>[src]

impl<T: Clone> FromIterator<T> for List<T>[src]

impl<T: PartialEq> PartialEq<List<T>> for List<T>[src]

Auto Trait Implementations

impl<T> !RefUnwindSafe for List<T>[src]

impl<T> !Send for List<T>[src]

impl<T> !Sync for List<T>[src]

impl<T> Unpin for List<T>[src]

impl<T> !UnwindSafe for List<T>[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.