Skip to content

Commit 91fe99e

Browse files
author
Erik Rhodes
committed
renamed some items and improved docs for clarity
1 parent 0b49d8b commit 91fe99e

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,7 +1397,7 @@ pub trait Itertools : Iterator {
13971397
///
13981398
/// The [`.take_while()`][std::iter::Iterator::take_while] adaptor is useful
13991399
/// when you want items satisfying a predicate, but to know when to stop
1400-
/// taking elements, we have to consume that last element that doesn't
1400+
/// taking elements, we have to consume that first element that doesn't
14011401
/// satisfy the predicate. This adaptor includes that element where
14021402
/// [`.take_while()`][std::iter::Iterator::take_while] would drop it.
14031403
///
@@ -1407,7 +1407,6 @@ pub trait Itertools : Iterator {
14071407
///
14081408
/// ```rust
14091409
/// # use itertools::Itertools;
1410-
///
14111410
/// let items = vec![1, 2, 3, 4, 5];
14121411
/// let filtered: Vec<_> = items
14131412
/// .into_iter()
@@ -1421,18 +1420,20 @@ pub trait Itertools : Iterator {
14211420
/// # use itertools::Itertools;
14221421
/// let items = vec![1, 2, 3, 4, 5];
14231422
///
1424-
/// let take_until_result: Vec<_> = items
1425-
/// .clone()
1426-
/// .into_iter()
1423+
/// let take_while_inclusive_result: Vec<_> = items
1424+
/// .iter()
1425+
/// .copied()
14271426
/// .take_while_inclusive(|&n| n % 3 != 0)
14281427
/// .collect();
14291428
/// let take_while_result: Vec<_> = items
14301429
/// .into_iter()
14311430
/// .take_while(|&n| n % 3 != 0)
14321431
/// .collect();
14331432
///
1434-
/// assert_eq!(take_until_result, vec![1, 2, 3]);
1433+
/// assert_eq!(take_while_inclusive_result, vec![1, 2, 3]);
14351434
/// assert_eq!(take_while_result, vec![1, 2]);
1435+
/// // both iterators have the same items remaining at this point---the 3
1436+
/// // is lost from the `take_while` vec
14361437
/// ```
14371438
///
14381439
/// ```rust
@@ -2763,7 +2764,6 @@ pub trait Itertools : Iterator {
27632764
/// itertools::assert_equal(oldest_people_first,
27642765
/// vec!["Jill", "Jack", "Jane", "John"]);
27652766
/// ```
2766-
/// ```
27672767
#[cfg(feature = "use_alloc")]
27682768
fn sorted_by_cached_key<K, F>(self, f: F) -> VecIntoIter<Self::Item>
27692769
where

src/take_while_inclusive.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
use core::iter::FusedIterator;
22
use std::fmt;
33

4-
/// An iterator adaptor that consumes elements while the given predicate is `true`, including the
5-
/// element for which the predicate first returned `false`.
4+
/// An iterator adaptor that consumes elements while the given predicate is
5+
/// `true`, including the element for which the predicate first returned
6+
/// `false`.
67
///
7-
/// See [`.take_while_inclusive()`](crate::Itertools::take_while_inclusive) for more information.
8+
/// See [`.take_while_inclusive()`](crate::Itertools::take_while_inclusive)
9+
/// for more information.
810
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
911
pub struct TakeWhileInclusive<'a, I: 'a, F> {
1012
iter: &'a mut I,
11-
f: F,
13+
predicate: F,
1214
done: bool,
1315
}
1416

@@ -18,8 +20,8 @@ where
1820
F: FnMut(&I::Item) -> bool,
1921
{
2022
/// Create a new [`TakeWhileInclusive`] from an iterator and a predicate.
21-
pub fn new(iter: &'a mut I, f: F) -> Self {
22-
Self { iter, f, done: false}
23+
pub fn new(iter: &'a mut I, predicate: F) -> Self {
24+
Self { iter, predicate, done: false}
2325
}
2426
}
2527

@@ -41,7 +43,7 @@ where
4143
None
4244
} else {
4345
self.iter.next().map(|item| {
44-
if !(self.f)(&item) {
46+
if !(self.predicate)(&item) {
4547
self.done = true;
4648
}
4749
item

0 commit comments

Comments
 (0)