Skip to content

Commit 0d741ab

Browse files
Philippe-Choletphimuemue
authored andcommitted
Deprecate group_by in favor of chunk_by
1 parent 1f69c53 commit 0d741ab

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/groupbylazy.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ where
294294
/// value. It should be stored in a local variable or temporary and
295295
/// iterated.
296296
///
297-
/// See [`.group_by()`](crate::Itertools::group_by) for more information.
297+
/// See [`.chunk_by()`](crate::Itertools::chunk_by) for more information.
298298
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
299299
pub struct GroupBy<K, I, F>
300300
where
@@ -368,7 +368,7 @@ where
368368
/// Iterator element type is `(K, Group)`:
369369
/// the group's key `K` and the group's iterator.
370370
///
371-
/// See [`.group_by()`](crate::Itertools::group_by) for more information.
371+
/// See [`.chunk_by()`](crate::Itertools::chunk_by) for more information.
372372
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
373373
pub struct Groups<'a, K, I, F>
374374
where

src/lib.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
//! - `use_std`
3838
//! - Enabled by default.
3939
//! - Disable to compile itertools using `#![no_std]`. This disables
40-
//! any items that depend on collections (like `group_by`, `unique`,
40+
//! any items that depend on collections (like `chunk_by`, `unique`,
4141
//! `kmerge`, `join` and many more).
4242
//!
4343
//! ## Rust Version
@@ -600,13 +600,13 @@ pub trait Itertools: Iterator {
600600
/// // Note: The `&` is significant here, `GroupBy` is iterable
601601
/// // only by reference. You can also call `.into_iter()` explicitly.
602602
/// let mut data_grouped = Vec::new();
603-
/// for (key, group) in &data.into_iter().group_by(|elt| *elt >= 0) {
603+
/// for (key, group) in &data.into_iter().chunk_by(|elt| *elt >= 0) {
604604
/// data_grouped.push((key, group.collect()));
605605
/// }
606606
/// assert_eq!(data_grouped, vec![(true, vec![1, 3]), (false, vec![-2, -2]), (true, vec![1, 0, 1, 2])]);
607607
/// ```
608608
#[cfg(feature = "use_alloc")]
609-
fn group_by<K, F>(self, key: F) -> GroupBy<K, Self, F>
609+
fn chunk_by<K, F>(self, key: F) -> GroupBy<K, Self, F>
610610
where
611611
Self: Sized,
612612
F: FnMut(&Self::Item) -> K,
@@ -615,6 +615,18 @@ pub trait Itertools: Iterator {
615615
groupbylazy::new(self, key)
616616
}
617617

618+
/// See [`.chunk_by()`](Itertools::chunk_by).
619+
#[deprecated(note = "Use .chunk_by() instead", since = "0.13.0")]
620+
#[cfg(feature = "use_alloc")]
621+
fn group_by<K, F>(self, key: F) -> GroupBy<K, Self, F>
622+
where
623+
Self: Sized,
624+
F: FnMut(&Self::Item) -> K,
625+
K: PartialEq,
626+
{
627+
self.chunk_by(key)
628+
}
629+
618630
/// Return an *iterable* that can chunk the iterator.
619631
///
620632
/// Yield subiterators (chunks) that each yield a fixed number elements,

0 commit comments

Comments
 (0)