Feature gate: `#![feature(slice_group_by)]` This is a tracking issue for the `GroupBy` and `GroupByMut` iterators. This feature exposes the `group_by` and `group_by_mut` methods on the slice and mutable slice types, these methods return the `GroupBy` and `GroupByMut` iterators structs respectively. Those two iterators return subslices of the original slice where a user-defined function returns `true` for two following elements of the slice. ### Public API These methods can return subslices that contains equal elements: ```rust let slice = &[1, 1, 1, 3, 3, 2, 2, 2]; let mut iter = slice.group_by(|a, b| a == b); assert_eq!(iter.next(), Some(&[1, 1, 1][..])); assert_eq!(iter.next(), Some(&[3, 3][..])); assert_eq!(iter.next(), Some(&[2, 2, 2][..])); assert_eq!(iter.next(), None); ``` they can also be used to extract the sorted subslices: ```rust let slice = &[1, 1, 2, 3, 2, 3, 2, 3, 4]; let mut iter = slice.group_by(|a, b| a <= b); assert_eq!(iter.next(), Some(&[1, 1, 2, 3][..])); assert_eq!(iter.next(), Some(&[2, 3][..])); assert_eq!(iter.next(), Some(&[2, 3, 4][..])); assert_eq!(iter.next(), None); ``` ### Steps / History - [x] Initial RFC discussion: https://github.com/rust-lang/rfcs/pull/2477 (it was determined that an RFC wasn't needed) - [x] Implementation: https://github.com/rust-lang/rust/pull/79895 - [ ] Stabilization PR ### Unresolved Questions - Should this be `group_by`? Or should we reserve that name for another higher-level combinator? https://github.com/rust-lang/rfcs/pull/2477#issuecomment-753905571