Skip to content

Commit d7a2ae6

Browse files
committed
re-organize the iterator module a bit
1 parent ae1c9eb commit d7a2ae6

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

src/libcore/iterator.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ pub trait IteratorUtil<A> {
2222
// FIXME: #5898: should be called map
2323
fn transform<'r, B>(self, f: &'r fn(A) -> B) -> MapIterator<'r, A, B, Self>;
2424
fn filter<'r>(self, predicate: &'r fn(&A) -> bool) -> FilterIterator<'r, A, Self>;
25+
fn enumerate(self) -> EnumerateIterator<Self>;
2526
fn skip_while<'r>(self, predicate: &'r fn(&A) -> bool) -> SkipWhileIterator<'r, A, Self>;
2627
fn take_while<'r>(self, predicate: &'r fn(&A) -> bool) -> TakeWhileIterator<'r, A, Self>;
2728
fn skip(self, n: uint) -> SkipIterator<Self>;
2829
fn take(self, n: uint) -> TakeIterator<Self>;
29-
fn enumerate(self) -> EnumerateIterator<Self>;
3030
fn advance(&mut self, f: &fn(A) -> bool);
3131
}
3232

@@ -101,6 +101,21 @@ impl<A, B, T: Iterator<A>, U: Iterator<B>> Iterator<(A, B)> for ZipIterator<T, U
101101
}
102102
}
103103

104+
pub struct MapIterator<'self, A, B, T> {
105+
priv iter: T,
106+
priv f: &'self fn(A) -> B
107+
}
108+
109+
impl<'self, A, B, T: Iterator<A>> Iterator<B> for MapIterator<'self, A, B, T> {
110+
#[inline]
111+
fn next(&mut self) -> Option<B> {
112+
match self.iter.next() {
113+
Some(a) => Some((self.f)(a)),
114+
_ => None
115+
}
116+
}
117+
}
118+
104119
pub struct FilterIterator<'self, A, T> {
105120
priv iter: T,
106121
priv predicate: &'self fn(&A) -> bool
@@ -120,21 +135,6 @@ impl<'self, A, T: Iterator<A>> Iterator<A> for FilterIterator<'self, A, T> {
120135
}
121136
}
122137

123-
pub struct MapIterator<'self, A, B, T> {
124-
priv iter: T,
125-
priv f: &'self fn(A) -> B
126-
}
127-
128-
impl<'self, A, B, T: Iterator<A>> Iterator<B> for MapIterator<'self, A, B, T> {
129-
#[inline]
130-
fn next(&mut self) -> Option<B> {
131-
match self.iter.next() {
132-
Some(a) => Some((self.f)(a)),
133-
_ => None
134-
}
135-
}
136-
}
137-
138138
pub struct EnumerateIterator<T> {
139139
priv iter: T,
140140
priv count: uint

0 commit comments

Comments
 (0)