Trait adapton::catalog::collections::ListElim
[−]
[src]
pub trait ListElim<X>: Debug + Clone + Hash + PartialEq + Eq { fn elim<Res, NilF, ConsF, NameF>(
_: &Self,
_: NilF,
_: ConsF,
_: NameF
) -> Res
where
NilF: FnOnce(&Self) -> Res,
ConsF: FnOnce(&X, &Self) -> Res,
NameF: FnOnce(&Name, &Self) -> Res; fn elim_arg<Arg, Res, NilF, ConsF, NameF>(
_: Self,
_: Arg,
_: NilF,
_: ConsF,
_: NameF
) -> Res
where
NilF: FnOnce(Self, Arg) -> Res,
ConsF: FnOnce(X, Self, Arg) -> Res,
NameF: FnOnce(Name, Self, Arg) -> Res; fn is_empty(list: &Self) -> bool { ... } fn is_name(list: &Self) -> bool { ... } }
Types that can be pattern-matched like a list of X
are ListElim<X>
.
We consider iterators to be a similar (nearly analogous) trait.
The key distinction here are that list elimination is a pattern-match used with (pure) recursion,
as opposed to an imperative for-loop, as is typical of iteration;
further, lists in Adapton contain data (of type X
) and names (of type Name
).
Required Methods
fn elim<Res, NilF, ConsF, NameF>(_: &Self, _: NilF, _: ConsF, _: NameF) -> Res where
NilF: FnOnce(&Self) -> Res,
ConsF: FnOnce(&X, &Self) -> Res,
NameF: FnOnce(&Name, &Self) -> Res,
NilF: FnOnce(&Self) -> Res,
ConsF: FnOnce(&X, &Self) -> Res,
NameF: FnOnce(&Name, &Self) -> Res,
Eliminate a list with the given functions (for the pattern match
arms) that handle the nil
, cons
and name
cases.
Eliminates the art
case internally, by forcing the art and
eliminating the resulting list with the given handler functions;
forces multiple art
cases, if need be.
fn elim_arg<Arg, Res, NilF, ConsF, NameF>(
_: Self,
_: Arg,
_: NilF,
_: ConsF,
_: NameF
) -> Res where
NilF: FnOnce(Self, Arg) -> Res,
ConsF: FnOnce(X, Self, Arg) -> Res,
NameF: FnOnce(Name, Self, Arg) -> Res,
_: Self,
_: Arg,
_: NilF,
_: ConsF,
_: NameF
) -> Res where
NilF: FnOnce(Self, Arg) -> Res,
ConsF: FnOnce(X, Self, Arg) -> Res,
NameF: FnOnce(Name, Self, Arg) -> Res,
Like elim
, except that the functions are given an additional
argument. This variant is needed due to the move semantics of
Rust. The argument is moved into the body of the activated
handler function when it is applied.
Provided Methods
fn is_empty(list: &Self) -> bool
Tests if the list contains any cons
cells. Derived from elim
.
fn is_name(list: &Self) -> bool
Tests if the head of the list consists of a name
constructor. Derived from elim
.