add reverse, snippet for prepend implementation

This commit is contained in:
Ava Hahn 2023-03-08 20:59:22 -08:00
parent 6961fcc9fa
commit 928c9b91ed
Signed by untrusted user who does not match committer: affine
GPG key ID: 3A4645B8CF806069
6 changed files with 288 additions and 25 deletions

View file

@ -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,