Skip to content

Commit e89ea0d

Browse files
bors[bot]phimuemue
andauthored
Merge #375
375: Clarify documentation for group_by r=jswrenn a=phimuemue This refers to #374 (comment). I tried to make the docs a bit clearer by `collect`ing into a vector, showing the groups explicitly. Co-authored-by: philipp <[email protected]>
2 parents ba24605 + 97c6265 commit e89ea0d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/lib.rs

+3-2
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)