From 0748b305934399a3e33b29335729b6eed25a46da Mon Sep 17 00:00:00 2001 From: timofey Date: Tue, 1 Aug 2023 20:07:59 +0000 Subject: [PATCH] simplify `EvalTree::next` --- src/func/instances/stackless.rs | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/func/instances/stackless.rs b/src/func/instances/stackless.rs index 0badc89..5d257fd 100644 --- a/src/func/instances/stackless.rs +++ b/src/func/instances/stackless.rs @@ -48,18 +48,22 @@ enum EvalTree<'a> { type Oet<'a> = Option>; impl<'a> EvalTree<'a> { + fn _next_composite(self, other: Box) -> Self { + match self { + Self::Atom(f) => match f.next() { + Some(newleft) => Self::Composite(Box::new(newleft), other), + None => *other, + }, + Self::Composite(etll, etlr) => { + Self::Composite(etll, Box::new(Self::Composite(etlr, other))) + } + } + } + fn next(self) -> Oet<'a> { match self { Self::Atom(f) => f.next(), - Self::Composite(etl, etr) => match *etl { - Self::Atom(f) => match f.next() { - Some(newleft) => Some(Self::Composite(Box::new(newleft), etr)), - None => Some(*etr), - }, - Self::Composite(etll, etlr) => { - Some(Self::Composite(etll, Box::new(Self::Composite(etlr, etr)))) - } - }, + Self::Composite(etl, etr) => Some(etl._next_composite(etr)), } } }