-
Notifications
You must be signed in to change notification settings - Fork 496
Iterator Trait Parity
Niko Matsakis edited this page Nov 17, 2016
·
13 revisions
Here is a copy of the current Iterator
trait along with some annotations on each of its methods:
pub trait Iterator {
type Item;
fn next(&mut self) -> Option<Self::Item>;
N/A fn size_hint(&self) -> (usize, Option<usize>) { ... }
DONE fn count(self) -> usize { ... }
N/A fn last(self) -> Option<Self::Item> { ... }
N/A fn nth(&mut self, n: usize) -> Option<Self::Item> { ... }
DONE fn chain<U>(self, other: U) -> Chain<Self, U::IntoIter> where U: IntoIterator<Item=Self::Item> { ... }
DONE fn zip<U>(self, other: U) -> Zip<Self, U::IntoIter> where U: IntoIterator { ... }
DONE fn map<B, F>(self, f: F) -> Map<Self, F> where F: FnMut(Self::Item) -> B { ... }
DONE fn filter<P>(self, predicate: P) -> Filter<Self, P> where P: FnMut(&Self::Item) -> bool { ... }
DONE fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F> where F: FnMut(Self::Item) -> Option<B> { ... }
DONE fn enumerate(self) -> Enumerate<Self> { ... }
N/A fn peekable(self) -> Peekable<Self> { ... }
fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P> where P: FnMut(&Self::Item) -> bool { ... }
fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P> where P: FnMut(&Self::Item) -> bool { ... }
EASY fn skip(self, n: usize) -> Skip<Self> { ... }
- seems easy on a ExactLengthIterator; just split_at(n) and discard one side, right?
- otherwise, seems very hard
EASY fn take(self, n: usize) -> Take<Self> { ... }
- seems easy on a ExactLengthIterator; just split_at(len - n) and discard one side, right?
- otherwise...seems hard.
HARD fn scan<St, B, F>(self, initial_state: St, f: F) -> Scan<Self, St, F> where F: FnMut(&mut St, Self::Item) -> Option<B> { ... }
DONE fn flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F> where F: FnMut(Self::Item) -> U, U: IntoIterator { ... }
MEH fn fuse(self) -> Fuse<Self> { ... }
DONE fn inspect<F>(self, f: F) -> Inspect<Self, F> where F: FnMut(&Self::Item) -> () { ... }
MEH fn by_ref(&mut self) -> &mut Self { ... }
#124 fn collect<B>(self) -> B where B: FromIterator<Self::Item> { ... }
HMM fn partition<B, F>(self, f: F) -> (B, B) where B: Default + Extend<Self::Item>, F: FnMut(&Self::Item) -> bool { ... }
- I've always thought this signature was wrong. Trying to remember why. =)
- At minimum, it should permit two distinct kinds of collections.
- Still, it's interesting that the current FromParallelIterator can't support this.
DONE fn fold<B, F>(self, init: B, f: F) -> B where F: FnMut(B, Self::Item) -> B { ... }
DONE fn all<F>(&mut self, f: F) -> bool where F: FnMut(Self::Item) -> bool { ... }
DONE fn any<F>(&mut self, f: F) -> bool where F: FnMut(Self::Item) -> bool { ... }
PARTIAL fn find<P>(&mut self, predicate: P) -> Option<Self::Item> where P: FnMut(&Self::Item) -> bool { ... }
PARTIAL fn position<P>(&mut self, predicate: P) -> Option<usize> where P: FnMut(Self::Item) -> bool { ... }
PARTIAL fn rposition<P>(&mut self, predicate: P) -> Option<usize> where P: FnMut(Self::Item) -> bool, Self: ExactSizeIterator + DoubleEndedIterator { ... }
DONE fn max(self) -> Option<Self::Item> where Self::Item: Ord { ... }
DONE fn min(self) -> Option<Self::Item> where Self::Item: Ord { ... }
EASY fn max_by_key<B, F>(self, f: F) -> Option<Self::Item> where B: Ord, F: FnMut(&Self::Item) -> B { ... }
EASY fn min_by_key<B, F>(self, f: F) -> Option<Self::Item> where B: Ord, F: FnMut(&Self::Item) -> B { ... }
EASY? fn rev(self) -> Rev<Self> where Self: DoubleEndedIterator { ... }
- would require Exact iterator
- maybe easy? maybe requires tweaks to producer...
HMM fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB) where FromA: Default + Extend<A>, FromB: Default + Extend<B>, Self: Iterator<Item=(A, B)> { ... }
- like partition, a bit tricky
DONE fn cloned<'a, T>(self) -> Cloned<Self> where Self: Iterator<Item=&'a T>, T: 'a + Clone { ... }
fn cycle(self) -> Cycle<Self> where Self: Clone { ... }
DONE fn sum<S>(self) -> S where S: Sum<Self::Item> { ... }
DONE fn product<P>(self) -> P where P: Product<Self::Item> { ... }
EASY fn cmp<I>(self, other: I) -> Ordering where I: IntoIterator<Item=Self::Item>, Self::Item: Ord { ... }
EASY fn partial_cmp<I>(self, other: I) -> Option<Ordering> where I: IntoIterator, Self::Item: PartialOrd<I::Item> { ... }
EASY fn eq<I>(self, other: I) -> bool where I: IntoIterator, Self::Item: PartialEq<I::Item> { ... }
EASY fn ne<I>(self, other: I) -> bool where I: IntoIterator, Self::Item: PartialEq<I::Item> { ... }
EASY fn lt<I>(self, other: I) -> bool where I: IntoIterator, Self::Item: PartialOrd<I::Item> { ... }
EASY fn le<I>(self, other: I) -> bool where I: IntoIterator, Self::Item: PartialOrd<I::Item> { ... }
EASY fn gt<I>(self, other: I) -> bool where I: IntoIterator, Self::Item: PartialOrd<I::Item> { ... }
EASY fn ge<I>(self, other: I) -> bool where I: IntoIterator, Self::Item: PartialOrd<I::Item> { ... }
}