Skip to content

Commit 97c6265

Browse files
committed
Clarify documentation for group_by
1 parent 340e06f commit 97c6265

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,10 +505,11 @@ pub trait Itertools : Iterator {
505505
///
506506
/// // Note: The `&` is significant here, `GroupBy` is iterable
507507
/// // only by reference. You can also call `.into_iter()` explicitly.
508+
/// let mut data_grouped = Vec::new();
508509
/// for (key, group) in &data.into_iter().group_by(|elt| *elt >= 0) {
509-
/// // Check that the sum of each group is +/- 4.
510-
/// assert_eq!(4, group.sum::<i32>().abs());
510+
/// data_grouped.push((key, group.collect()));
511511
/// }
512+
/// assert_eq!(data_grouped, vec![(true, vec![1, 3]), (false, vec![-2, -2]), (true, vec![1, 0, 1, 2])]);
512513
/// ```
513514
#[cfg(feature = "use_std")]
514515
fn group_by<K, F>(self, key: F) -> GroupBy<K, Self, F>

0 commit comments

Comments
 (0)