pub struct List<T: Obj>(/* private fields */);Expand description
Garbage-collected Vec-like datastructure implementing Copy.
Note that functions which seem to mutate the List, actually clone the list and allocate a new GcCow under the hood.
Implementations§
source§impl<T: Obj> List<T>
impl<T: Obj> List<T>
sourcepub fn iter(&self) -> ConsumingIter<T>
pub fn iter(&self) -> ConsumingIter<T>
An ordered iterator over all elements of List.
source§impl<T: Obj> List<T>
impl<T: Obj> List<T>
sourcepub fn mutate_at<O: Obj>(&mut self, i: Int, f: impl FnOnce(&mut T) -> O) -> O
pub fn mutate_at<O: Obj>(&mut self, i: Int, f: impl FnOnce(&mut T) -> O) -> O
Conceptually equivalent to f(&mut self[i]).
Mutates the ith element by giving a mutable ref of it into the function f.
The return value of f will be returned from mutate_at.
Instead of actual mutation, a new list is allocated, where only the ith element is changed.
Then self is changed so that it points to that new list.
sourcepub fn try_mutate_at<O: Obj, E>(
&mut self,
i: Int,
f: impl FnOnce(&mut T) -> NdResult<O, E>,
) -> NdResult<O, E>
pub fn try_mutate_at<O: Obj, E>( &mut self, i: Int, f: impl FnOnce(&mut T) -> NdResult<O, E>, ) -> NdResult<O, E>
Like mutate_at, but the closure is fallible
sourcepub fn index_at(&self, i: impl Into<Int>) -> T
pub fn index_at(&self, i: impl Into<Int>) -> T
The indexing operator:
specr translates a[b] to a.index_at(b).
sourcepub fn pop(&mut self) -> Option<T>
pub fn pop(&mut self) -> Option<T>
Pop the element from the end of the list.
Returns None is the list was empty.
sourcepub fn pop_front(&mut self) -> Option<T>
pub fn pop_front(&mut self) -> Option<T>
Pop the element from the beginning of the list.
Returns None is the list was empty.
sourcepub fn subslice_with_length(&self, start: Int, length: Int) -> List<T>
pub fn subslice_with_length(&self, start: Int, length: Int) -> List<T>
Conceptually equivalent to self[start..length].
sourcepub fn write_subslice_at_index(&mut self, start: Int, src: List<T>)
pub fn write_subslice_at_index(&mut self, start: Int, src: List<T>)
Conceptually equivalent to self[start..src.len()] = src;
sourcepub fn sort_by_key<K: Obj + Ord>(&mut self, f: impl FnMut(T) -> K)
pub fn sort_by_key<K: Obj + Ord>(&mut self, f: impl FnMut(T) -> K)
Sorts the list with a key extraction function.
sourcepub fn zip<T2: Obj>(self, other: List<T2>) -> List<(T, T2)>
pub fn zip<T2: Obj>(self, other: List<T2>) -> List<(T, T2)>
Combine two lists to a list of pairs.
sourcepub fn any(self, f: impl FnMut(T) -> bool) -> bool
pub fn any(self, f: impl FnMut(T) -> bool) -> bool
Tests if any element of the list matches a predicate.
sourcepub fn all(self, f: impl FnMut(T) -> bool) -> bool
pub fn all(self, f: impl FnMut(T) -> bool) -> bool
Tests if all elements of the list matches a predicate.
sourcepub fn map<O: Obj>(self, f: impl FnMut(T) -> O) -> List<O>
pub fn map<O: Obj>(self, f: impl FnMut(T) -> O) -> List<O>
applies f to each element of the list and returns the outputs as another list.
sourcepub fn flat_map<O: Obj>(self, f: impl FnMut(T) -> List<O>) -> List<O>
pub fn flat_map<O: Obj>(self, f: impl FnMut(T) -> List<O>) -> List<O>
Works like map, but flattens nested structure.