[−][src]Struct functional_list::List
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>ⓘ
[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]
&'s self,
f: impl FnMut(Option<&'s T>, &'s T) -> Option<&'s T>
) -> Option<&'s T>
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]
impl<T> List<List<T>>
[src]
impl<K, V> List<(K, V)> where
K: Eq,
[src]
K: Eq,
pub fn get<Q: ?Sized>(&self, key: &Q) -> Option<&V> where
K: Borrow<Q>,
Q: Eq,
[src]
K: Borrow<Q>,
Q: Eq,
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]
pub fn clone(&self) -> Self
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[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]
pub fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
[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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,