Skip to content

Commit 6f8c887

Browse files
committed
---
yaml --- r: 139807 b: refs/heads/try2 c: f82c964 h: refs/heads/master i: 139805: 1a6921d 139803: bcec489 139799: c8b5788 139791: dfb2629 139775: 2db0e9c v: v3
1 parent 6e4b12d commit 6f8c887

File tree

3 files changed

+41
-36
lines changed

3 files changed

+41
-36
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: a581926f57d8fe9afaa792f26240ad1ff1288377
8+
refs/heads/try2: f82c96446f7577cc29c71ed793a531c9189e7039
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libcore/iterator.rs

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,46 @@
1212
1313
use prelude::*;
1414

15-
pub trait Iterator<T> {
15+
pub trait Iterator<A> {
1616
/// Advance the iterator and return the next value. Return `None` when the end is reached.
17-
fn next(&mut self) -> Option<T>;
17+
fn next(&mut self) -> Option<A>;
1818
}
1919

20-
/// A shim implementing the `for` loop iteration protocol for iterator objects
21-
#[inline]
22-
pub fn advance<T, U: Iterator<T>>(iter: &mut U, f: &fn(T) -> bool) {
23-
loop {
24-
match iter.next() {
25-
Some(x) => {
26-
if !f(x) { return }
20+
pub trait IteratorUtil<A> {
21+
fn zip<B, U: Iterator<B>>(self, other: U) -> ZipIterator<Self, U>;
22+
// FIXME: #5898: should be called map
23+
fn transform<'r, B>(self, f: &'r fn(A) -> B) -> MapIterator<'r, A, B, Self>;
24+
fn filter<'r>(self, predicate: &'r fn(&A) -> bool) -> FilterIterator<'r, A, Self>;
25+
fn advance(&mut self, f: &fn(A) -> bool);
26+
}
27+
28+
impl<A, T: Iterator<A>> IteratorUtil<A> for T {
29+
#[inline(always)]
30+
fn zip<B, U: Iterator<B>>(self, other: U) -> ZipIterator<T, U> {
31+
ZipIterator{a: self, b: other}
32+
}
33+
34+
// FIXME: #5898: should be called map
35+
#[inline(always)]
36+
fn transform<'r, B>(self, f: &'r fn(A) -> B) -> MapIterator<'r, A, B, T> {
37+
MapIterator{iter: self, f: f}
38+
}
39+
40+
#[inline(always)]
41+
fn filter<'r>(self, predicate: &'r fn(&A) -> bool) -> FilterIterator<'r, A, T> {
42+
FilterIterator{iter: self, predicate: predicate}
43+
}
44+
45+
/// A shim implementing the `for` loop iteration protocol for iterator objects
46+
#[inline]
47+
fn advance(&mut self, f: &fn(A) -> bool) {
48+
loop {
49+
match self.next() {
50+
Some(x) => {
51+
if !f(x) { return }
52+
}
53+
None => return
2754
}
28-
None => return
2955
}
3056
}
3157
}
@@ -35,13 +61,6 @@ pub struct ZipIterator<T, U> {
3561
priv b: U
3662
}
3763

38-
pub impl<A, B, T: Iterator<A>, U: Iterator<B>> ZipIterator<T, U> {
39-
#[inline(always)]
40-
fn new(a: T, b: U) -> ZipIterator<T, U> {
41-
ZipIterator{a: a, b: b}
42-
}
43-
}
44-
4564
impl<A, B, T: Iterator<A>, U: Iterator<B>> Iterator<(A, B)> for ZipIterator<T, U> {
4665
#[inline]
4766
fn next(&mut self) -> Option<(A, B)> {
@@ -57,17 +76,10 @@ pub struct FilterIterator<'self, A, T> {
5776
priv predicate: &'self fn(&A) -> bool
5877
}
5978

60-
pub impl<'self, A, T: Iterator<A>> FilterIterator<'self, A, T> {
61-
#[inline(always)]
62-
fn new(iter: T, predicate: &'self fn(&A) -> bool) -> FilterIterator<'self, A, T> {
63-
FilterIterator{iter: iter, predicate: predicate}
64-
}
65-
}
66-
6779
impl<'self, A, T: Iterator<A>> Iterator<A> for FilterIterator<'self, A, T> {
6880
#[inline]
6981
fn next(&mut self) -> Option<A> {
70-
for advance(self) |x| {
82+
for self.iter.advance |x| {
7183
if (self.predicate)(&x) {
7284
return Some(x);
7385
} else {
@@ -83,13 +95,6 @@ pub struct MapIterator<'self, A, B, T> {
8395
priv f: &'self fn(A) -> B
8496
}
8597

86-
pub impl<'self, A, B, T: Iterator<A>> MapIterator<'self, A, B, T> {
87-
#[inline(always)]
88-
fn new(iter: T, f: &'self fn(A) -> B) -> MapIterator<'self, A, B, T> {
89-
MapIterator{iter: iter, f: f}
90-
}
91-
}
92-
9398
impl<'self, A, B, T: Iterator<A>> Iterator<B> for MapIterator<'self, A, B, T> {
9499
#[inline]
95100
fn next(&mut self) -> Option<B> {

branches/try2/src/libstd/treemap.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ mod test_treemap {
996996
(&x5, &y5)];
997997
let mut i = 0;
998998

999-
for advance(&mut b) |x| {
999+
for b.advance |x| {
10001000
assert!(expected[i] == x);
10011001
i += 1;
10021002

@@ -1005,7 +1005,7 @@ mod test_treemap {
10051005
}
10061006
}
10071007

1008-
for advance(&mut b) |x| {
1008+
for b.advance |x| {
10091009
assert!(expected[i] == x);
10101010
i += 1;
10111011
}
@@ -1209,7 +1209,7 @@ mod test_set {
12091209

12101210
let x = x;
12111211
let y = y;
1212-
let mut z = ZipIterator::new(x.iter(), y.iter());
1212+
let mut z = x.iter().zip(y.iter());
12131213

12141214
// FIXME: #5801: this needs a type hint to compile...
12151215
let result: Option<(&uint, & &'static str)> = z.next();

0 commit comments

Comments
 (0)