-
Couldn't load subscription status.
- Fork 13.9k
Open
Labels
A-iteratorsArea: IteratorsArea: IteratorsC-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 RFCT-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.
Description
Feature gate: #![feature(iter_dedup)]
This is a tracking issue for the functions std::iter::Iterator::{dedup, dedup_by, dedup_by_key} as well as the structs std::iter::{Dedup, ByKey, ByPartialEq}.
This feature provides similar functionality as the functions for slices and Vecs with the same name:
let vec = vec![1, 2, 2, 3, 2];
let mut iter = vec.into_iter().dedup();
assert_eq!(iter.next(), Some(1));
assert_eq!(iter.next(), Some(2));
assert_eq!(iter.next(), Some(3));
assert_eq!(iter.next(), Some(2));
assert_eq!(iter.next(), None);Public API
pub trait Iterator {
/// Removes all but the first of consecutive elements in the iterator
/// according to the `PartialEq` trait implementation.
fn dedup(self) -> Dedup<Self, ByPartialEq>
where
Self: Sized,
Self::Item: PartialEq,
{ ... }
/// Removes all but the first of consecutive elements in the iterator
/// satisfying a given equality relation.
fn dedup_by<F>(self, same_bucket: F) -> Dedup<Self, F>
where
Self: Sized,
F: FnMut(&Self::Item, &Self::Item) -> bool,
{ ... }
/// Removes all but the first of consecutive elements in the iterator
/// that resolve to the same key.
fn dedup_by_key<F, K>(self, key: F) -> Dedup<Self, ByKey<F>>
where
Self: Sized,
F: FnMut(&Self::Item) -> K,
K: PartialEq,
{ ... }
}Steps / History
- Implementation: Add
dedup,dedup_byanddedup_by_keyto theIteratortrait #83748 - Final commenting period (FCP)
- Stabilization PR
Unresolved Questions
Is there a way to reducededupanddedup_by_keyto a call todedup_bywithout creating an impossible function signature?Should we also implementSourceIterandInPlaceIterablefor these structs?How should/can we react to an infinite iterator where all items are the same?Is there a way to turn this into a no-op for iterators which cannot contain duplicates (e.g.hashset.iter().dedup())?
AngelicosPhosphoros, mark-i-m, a0000778 and bbb651leonardo-m and bbb651
Metadata
Metadata
Assignees
Labels
A-iteratorsArea: IteratorsArea: IteratorsC-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 RFCT-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.