Skip to content

Commit cb06691

Browse files
Update CombinationsWithReplacement::next (2)
Use `pool.get_at` once! That way, `next` and `nth` will ressemble each other.
1 parent cd1ed15 commit cb06691

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

src/combinations_with_replacement.rs

+5-12
Original file line numberDiff line numberDiff line change
@@ -94,22 +94,15 @@ where
9494
type Item = Vec<I::Item>;
9595

9696
fn next(&mut self) -> Option<Self::Item> {
97-
// If this is the first iteration, return early
9897
if self.first {
9998
// In empty edge cases, stop iterating immediately
100-
return if !(self.indices.is_empty() || self.pool.get_next()) {
101-
None
102-
// Otherwise, yield the initial state
103-
} else {
104-
self.first = false;
105-
Some(self.pool.get_at(&self.indices))
106-
};
107-
}
108-
109-
if self.increment_indices() {
99+
if !(self.indices.is_empty() || self.pool.get_next()) {
100+
return None;
101+
}
102+
self.first = false;
103+
} else if self.increment_indices() {
110104
return None;
111105
}
112-
113106
Some(self.pool.get_at(&self.indices))
114107
}
115108

0 commit comments

Comments
 (0)