forall T, 'k.
enum List { ... }
A persistent singly linked list in an arena: a cell holding the first element and the rest, or the empty list. Restricted: a list is made by empty, cons and the functions that build one, and read through its methods.
Methods
method emptysource
fn empty() -> List[T, 'k] { ... }
The list with no elements.
method conssource
forall C, R where Copy[T], Allocate[C -> 'k, R].
fn cons(self, &cx: C, head: T) -> List[T, 'k] { ... }
Prepends head. The cell is arena-allocated, so it needs no free of its own; the whole arena is freed as a unit. T is Copy, as everything in an arena is.
method is_emptysource
fn is_empty(self) -> bool { ... }
Whether the list has no elements.
method popsource
forall C, R where Access[C -> 'k, R].
fn pop(&self, &cx: C) -> Option[T] { ... }
The first element, leaving the rest in self: a loop over a list whose body needs the context.
method lensource
forall C, R where Access[C -> 'k, R].
fn len(self, &cx: C) -> usize { ... }
How many elements the list has, counted cell by cell.
method appendsource
forall C, R, Q where Access[C -> 'k, R], Allocate[C -> 'k, Q].
fn append(self, &cx: C, other: List[T, 'k]) -> List[T, 'k] { ... }
The elements of self, copied into new cells, followed by other.
method reversesource
forall C, R, Q where Access[C -> 'k, R], Allocate[C -> 'k, Q].
fn reverse(self, &cx: C, acc: List[T, 'k]) -> List[T, 'k] { ... }
Reverses self onto the front of acc; a nonempty acc merges the list onto a running result.
method nthsource
forall C, R where Access[C -> 'k, R].
fn nth(self, &cx: C, index: usize) -> Option[T] { ... }
The element at index, counting from 0, if the list is that long.
method firstsource
forall C, R where Access[C -> 'k, R].
fn first(self, &cx: C) -> Option[T] { ... }
The first element, or None when the list is empty.
method tailsource
forall C, R where Access[C -> 'k, R].
fn tail(self, &cx: C) -> List[T, 'k] { ... }
The list without its first element (empty when it is empty).
method skipsource
forall C, R where Access[C -> 'k, R].
fn skip(self, &cx: C, count: usize) -> List[T, 'k] { ... }
The list without its first count elements.
method lastsource
forall C, R where Access[C -> 'k, R].
fn last(self, &cx: C) -> Option[T] { ... }
The last element, or None when the list is empty.
method eq_withsource
forall Env, C, R where Access[C -> 'k, R], Copy[Env].
fn eq_with(self, &cx: C, other: List[T, 'k], eq: closure[Env](&_: C, T, T) -> bool) -> bool { ... }
Whether both lists have the same length and eq holds pairwise, in order.
method find_mapsource
forall U, Env, C, R where Access[C -> 'k, R], Copy[U], Copy[Env].
fn find_map(self, &cx: C, f: closure[Env](&_: C, T) -> Option[U]) -> Option[U] { ... }
The first element f returns a value for, and that value.
method findsource
forall Env, C, R where Access[C -> 'k, R], Copy[Env].
fn find(self, &cx: C, f: closure[Env](&_: C, T) -> bool) -> Option[T] { ... }
The first element f holds for.
method anysource
forall Env, C, R where Access[C -> 'k, R], Copy[Env].
fn any(self, &cx: C, f: closure[Env](&_: C, T) -> bool) -> bool { ... }
Whether f holds for some element.
method allsource
forall Env, C, R where Access[C -> 'k, R], Copy[Env].
fn all(self, &cx: C, f: closure[Env](&_: C, T) -> bool) -> bool { ... }
Whether f holds for every element.
method eachsource
forall Env, C, R where Access[C -> 'k, R], Copy[Env].
fn each(self, &cx: C, f: closure[Env](&_: C, T) -> ()) { ... }
f on each element, for what it does through the context.
method countsource
forall Env, C, R where Access[C -> 'k, R], Copy[Env].
fn count(self, &cx: C, f: closure[Env](&_: C, T) -> bool) -> usize { ... }
How many elements f holds for.
method foldsource
forall A, Env, C, R where Access[C -> 'k, R], Copy[Env].
fn fold(self, &cx: C, acc: A, f: closure[Env](&_: C, A, T) -> A) -> A { ... }
acc through f with each element, head first.
method try_eachsource
forall E, Env, C, R where Access[C -> 'k, R], Copy[Env].
fn try_each(self, &cx: C, f: closure[Env](&_: C, T) -> Result[(), E]) -> Result[(), E] { ... }
f on each element, stopping at the first error.
method try_foldsource
forall A, E, Env, C, R where Access[C -> 'k, R], Copy[Env].
fn try_fold(self, &cx: C, acc: A, f: closure[Env](&_: C, A, T) -> Result[A, E]) -> Result[A, E] { ... }
acc through f with each element, stopping at the first error.
method mapsource
forall U, Env, C, R, Q where Access[C -> 'k, R], Allocate[C -> 'k, Q], Copy[U], Copy[Env].
fn map(self, &cx: C, f: closure[Env](&_: C, T) -> U) -> List[U, 'k] { ... }
Each element through f.
method filter_mapsource
forall U, Env, C, R, Q where Access[C -> 'k, R], Allocate[C -> 'k, Q], Copy[U], Copy[Env].
fn filter_map(self, &cx: C, f: closure[Env](&_: C, T) -> Option[U]) -> List[U, 'k] { ... }
The values f returns, skipping the elements it returns none for.
method filtersource
forall Env, C, R, Q where Access[C -> 'k, R], Allocate[C -> 'k, Q], Copy[Env].
fn filter(self, &cx: C, f: closure[Env](&_: C, T) -> bool) -> List[T, 'k] { ... }
The elements f holds for.
method try_mapsource
forall U, E, Env, C, R, Q where Access[C -> 'k, R], Allocate[C -> 'k, Q], Copy[U], Copy[Env].
fn try_map(self, &cx: C, f: closure[Env](&_: C, T) -> Result[U, E]) -> Result[List[U, 'k], E] { ... }
Each element through f, stopping at the first error.
method itersource
forall C, R where Access[C -> 'k, R].
fn iter(self, cx: C) -> ListIter![T, 'k, C, R] { ... }
An iterator over the list's elements, holding the context cx opens until ListIter!::finish hands it back.