add reverse, snippet for prepend implementation
This commit is contained in:
parent
6961fcc9fa
commit
928c9b91ed
6 changed files with 288 additions and 25 deletions
|
|
@ -126,6 +126,20 @@ impl Seg {
|
|||
}
|
||||
}
|
||||
|
||||
/* applies a function across a list in standard form
|
||||
* recurs before applying function to go in reverse
|
||||
* function must take a Ctr and return a bool
|
||||
* short circuits on the first false returned.
|
||||
* also returns false on a non standard form list
|
||||
*/
|
||||
pub fn circuit_reverse<F: FnMut(&Ctr) -> bool>(&self, func: &mut F) -> bool {
|
||||
match &*self.cdr {
|
||||
Ctr::None => func(&self.car),
|
||||
Ctr::Seg(l) => l.circuit_reverse(func) && func(&self.car),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_mono(arg: Box<Ctr>) -> Seg {
|
||||
Seg {
|
||||
car: arg,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue