Closed
Description
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:
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:
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
- Initial RFC discussion: RFC: Add the
group_by
andgroup_by_mut
methods to slice rfcs#2477 (it was determined that an RFC wasn't needed) - Implementation: The return of the GroupBy and GroupByMut iterators on slice #79895
- Stabilization PR
Unresolved Questions
- Should this be
group_by
? Or should we reserve that name for another higher-level combinator?
RFC: Add thegroup_by
andgroup_by_mut
methods to slice rfcs#2477 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Metadata
Assignees
Labels
Area: IteratorsArea: `[T]`Category: A tracking issue for an RFC or an unstable feature.Libs issues that are tracked on the team's project board.Relevant to the library API team, which will review and decide on the PR/issue.This issue / PR is in PFCP or FCP with a disposition to merge it.The final comment period is finished for this PR / Issue.