Skip to content

Commit b6efeb1

Browse files
committed
Add exhaust which simply exhausts the iterator
This is useful for iterators which are simply used for their side effects. The new function is added to make intent clearer for places where you'd previously call `count` or similar to exhaust the iterator.
1 parent 6ad9dba commit b6efeb1

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,6 +1530,13 @@ pub trait Itertools : Iterator {
15301530
|x, y, _, _| Ordering::Less == compare(x, y)
15311531
)
15321532
}
1533+
1534+
/// Exhaust the iterator by repeatedly calling `next()`.
1535+
fn exhaust(self)
1536+
where Self: Sized,
1537+
{
1538+
self.count();
1539+
}
15331540
}
15341541

15351542
impl<T: ?Sized> Itertools for T where T: Iterator { }

0 commit comments

Comments
 (0)