Skip to content

Commit

Permalink
Group related methods
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Dec 11, 2024
1 parent 3b29c87 commit 3b02881
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions experiments/2024-12-09/src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,25 @@ impl OperationView {
self.operations_inner(true, 0)
}

fn operations_inner(
&self,
selected: bool,
indent_level: usize,
) -> Box<dyn Iterator<Item = (&Self, bool, usize)> + '_> {
let self_ = iter::once((self, selected, indent_level));

if self.selected.is_some() {
Box::new(self_.chain(self.children.iter().enumerate().flat_map(
move |(i, view)| {
let selected = Some(i) == self.selected;
view.operations_inner(selected, indent_level + 1)
},
)))
} else {
Box::new(self_)
}
}

pub fn select_last(&mut self) {
self.selected = Some(self.last_index());
}
Expand All @@ -50,25 +69,6 @@ impl OperationView {
.unwrap_or(self)
}

fn operations_inner(
&self,
selected: bool,
indent_level: usize,
) -> Box<dyn Iterator<Item = (&Self, bool, usize)> + '_> {
let self_ = iter::once((self, selected, indent_level));

if self.selected.is_some() {
Box::new(self_.chain(self.children.iter().enumerate().flat_map(
move |(i, view)| {
let selected = Some(i) == self.selected;
view.operations_inner(selected, indent_level + 1)
},
)))
} else {
Box::new(self_)
}
}

fn last_index(&self) -> usize {
self.children.len().saturating_sub(1)
}
Expand Down

0 comments on commit 3b02881

Please sign in to comment.