Skip to content

Commit a9c465c

Browse files
committed
iterator: remove first
it's the same as `next.unwrap()`, but there's no way to check the length of an iterator so this isn't a good pattern
1 parent ac74bbe commit a9c465c

File tree

1 file changed

+0
-24
lines changed

1 file changed

+0
-24
lines changed

src/libcore/iterator.rs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ pub trait IteratorUtil<A> {
4949
fn advance(&mut self, f: &fn(A) -> bool) -> bool;
5050
fn to_vec(self) -> ~[A];
5151
fn nth(&mut self, n: uint) -> A;
52-
fn first(&mut self) -> A;
5352
fn last(&mut self) -> A;
5453
fn fold<B>(&mut self, start: B, f: &fn(B, A) -> B) -> B;
5554
fn count(&mut self) -> uint;
@@ -168,15 +167,6 @@ impl<A, T: Iterator<A>> IteratorUtil<A> for T {
168167
}
169168
}
170169

171-
// Get first elemet of an iterator.
172-
#[inline(always)]
173-
fn first(&mut self) -> A {
174-
match self.next() {
175-
Some(x) => x ,
176-
None => fail!("cannot get first element")
177-
}
178-
}
179-
180170
// Get last element of an iterator.
181171
//
182172
// If the iterator have an infinite length, this method won't return.
@@ -700,20 +690,6 @@ mod tests {
700690
v.iter().nth(5);
701691
}
702692

703-
#[test]
704-
fn test_iterator_first() {
705-
let v = &[0, 1, 2, 3, 4];
706-
assert_eq!(v.iter().first(), &0);
707-
assert_eq!(v.slice(2, 5).iter().first(), &2);
708-
}
709-
710-
#[test]
711-
#[should_fail]
712-
fn test_iterator_first_fail() {
713-
let v: &[uint] = &[];
714-
v.iter().first();
715-
}
716-
717693
#[test]
718694
fn test_iterator_last() {
719695
let v = &[0, 1, 2, 3, 4];

0 commit comments

Comments
 (0)