@@ -41,13 +41,6 @@ pub trait Extendable<A>: FromIterator<A> {
41
41
/// An interface for dealing with "external iterators". These types of iterators
42
42
/// can be resumed at any time as all state is stored internally as opposed to
43
43
/// being located on the call stack.
44
- ///
45
- /// The Iterator protocol states that an iterator yields a (potentially-empty,
46
- /// potentially-infinite) sequence of values, and returns `None` to signal that
47
- /// it's finished. The Iterator protocol does not define behavior after `None`
48
- /// is returned. A concrete Iterator implementation may choose to behave however
49
- /// it wishes, either by returning `None` infinitely, or by doing something
50
- /// else.
51
44
pub trait Iterator < A > {
52
45
/// Advance the iterator and return the next value. Return `None` when the end is reached.
53
46
fn next ( & mut self ) -> Option < A > ;
@@ -307,36 +300,6 @@ pub trait Iterator<A> {
307
300
FlatMap { iter : self , f : f, frontiter : None , backiter : None }
308
301
}
309
302
310
- /// Creates an iterator that yields `None` forever after the underlying
311
- /// iterator yields `None`. Random-access iterator behavior is not
312
- /// affected, only single and double-ended iterator behavior.
313
- ///
314
- /// # Example
315
- ///
316
- /// ~~~ {.rust}
317
- /// fn process<U: Iterator<int>>(it: U) -> int {
318
- /// let mut it = it.fuse();
319
- /// let mut sum = 0;
320
- /// for x in it {
321
- /// if x > 5 {
322
- /// break;
323
- /// }
324
- /// sum += x;
325
- /// }
326
- /// // did we exhaust the iterator?
327
- /// if it.next().is_none() {
328
- /// sum += 1000;
329
- /// }
330
- /// sum
331
- /// }
332
- /// let x = ~[1,2,3,7,8,9];
333
- /// assert_eq!(process(x.move_iter()), 1006);
334
- /// ~~~
335
- #[ inline]
336
- fn fuse ( self ) -> Fuse < Self > {
337
- Fuse { iter : self , done : false }
338
- }
339
-
340
303
/// Creates an iterator that calls a function with a reference to each
341
304
/// element before yielding it. This is often useful for debugging an
342
305
/// iterator pipeline.
@@ -929,12 +892,9 @@ pub struct Zip<T, U> {
929
892
impl < A , B , T : Iterator < A > , U : Iterator < B > > Iterator < ( A , B ) > for Zip < T , U > {
930
893
#[ inline]
931
894
fn next ( & mut self ) -> Option < ( A , B ) > {
932
- match self . a . next ( ) {
933
- None => None ,
934
- Some ( x) => match self . b . next ( ) {
935
- None => None ,
936
- Some ( y) => Some ( ( x, y) )
937
- }
895
+ match ( self . a . next ( ) , self . b . next ( ) ) {
896
+ ( Some ( x) , Some ( y) ) => Some ( ( x, y) ) ,
897
+ _ => None
938
898
}
939
899
}
940
900
@@ -965,12 +925,9 @@ RandomAccessIterator<(A, B)> for Zip<T, U> {
965
925
966
926
#[ inline]
967
927
fn idx ( & self , index : uint ) -> Option < ( A , B ) > {
968
- match self . a . idx ( index) {
969
- None => None ,
970
- Some ( x) => match self . b . idx ( index) {
971
- None => None ,
972
- Some ( y) => Some ( ( x, y) )
973
- }
928
+ match ( self . a . idx ( index) , self . b . idx ( index) ) {
929
+ ( Some ( x) , Some ( y) ) => Some ( ( x, y) ) ,
930
+ _ => None
974
931
}
975
932
}
976
933
}
@@ -1464,79 +1421,6 @@ impl<'self,
1464
1421
}
1465
1422
}
1466
1423
1467
- /// An iterator that yields `None` forever after the underlying iterator
1468
- /// yields `None` once.
1469
- #[ deriving( Clone , DeepClone ) ]
1470
- pub struct Fuse < T > {
1471
- priv iter : T ,
1472
- priv done : bool
1473
- }
1474
-
1475
- impl < A , T : Iterator < A > > Iterator < A > for Fuse < T > {
1476
- #[ inline]
1477
- fn next ( & mut self ) -> Option < A > {
1478
- if self . done {
1479
- None
1480
- } else {
1481
- match self . iter . next ( ) {
1482
- None => {
1483
- self . done = true ;
1484
- None
1485
- }
1486
- x => x
1487
- }
1488
- }
1489
- }
1490
-
1491
- #[ inline]
1492
- fn size_hint ( & self ) -> ( uint , Option < uint > ) {
1493
- if self . done {
1494
- ( 0 , Some ( 0 ) )
1495
- } else {
1496
- self . iter . size_hint ( )
1497
- }
1498
- }
1499
- }
1500
-
1501
- impl < A , T : DoubleEndedIterator < A > > DoubleEndedIterator < A > for Fuse < T > {
1502
- #[ inline]
1503
- fn next_back ( & mut self ) -> Option < A > {
1504
- if self . done {
1505
- None
1506
- } else {
1507
- match self . iter . next_back ( ) {
1508
- None => {
1509
- self . done = true ;
1510
- None
1511
- }
1512
- x => x
1513
- }
1514
- }
1515
- }
1516
- }
1517
-
1518
- // Allow RandomAccessIterators to be fused without affecting random-access behavior
1519
- impl < A , T : RandomAccessIterator < A > > RandomAccessIterator < A > for Fuse < T > {
1520
- #[ inline]
1521
- fn indexable ( & self ) -> uint {
1522
- self . iter . indexable ( )
1523
- }
1524
-
1525
- #[ inline]
1526
- fn idx ( & self , index : uint ) -> Option < A > {
1527
- self . iter . idx ( index)
1528
- }
1529
- }
1530
-
1531
- impl < T > Fuse < T > {
1532
- /// Resets the fuse such that the next call to .next() or .next_back() will
1533
- /// call the underlying iterator again even if it prevously returned None.
1534
- #[ inline]
1535
- fn reset_fuse ( & mut self ) {
1536
- self . done = false
1537
- }
1538
- }
1539
-
1540
1424
/// An iterator that calls a function with a reference to each
1541
1425
/// element before yielding it.
1542
1426
pub struct Inspect < ' self , A , T > {
0 commit comments