-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-iteratorsArea: IteratorsArea: IteratorsA-sliceArea: `[T]`Area: `[T]`C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCLibs-TrackedLibs issues that are tracked on the team's project board.Libs issues that are tracked on the team's project board.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
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)
marcospb19, sudormrfbin, mnnxp, danburkert, SonnyX and 29 morepatrickelectric, lokegustafsson, rsalmei, ensconced, Alphasite and 2 more
Metadata
Metadata
Assignees
Labels
A-iteratorsArea: IteratorsArea: IteratorsA-sliceArea: `[T]`Area: `[T]`C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCLibs-TrackedLibs issues that are tracked on the team's project board.Libs issues that are tracked on the team's project board.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.