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
This commit is contained in:
Daniel Micay 2013-05-18 04:20:01 -04:00
parent ac74bbec93
commit a9c465ce1f

View file

@ -49,7 +49,6 @@ pub trait IteratorUtil<A> {
fn advance(&mut self, f: &fn(A) -> bool) -> bool;
fn to_vec(self) -> ~[A];
fn nth(&mut self, n: uint) -> A;
fn first(&mut self) -> A;
fn last(&mut self) -> A;
fn fold<B>(&mut self, start: B, f: &fn(B, A) -> B) -> B;
fn count(&mut self) -> uint;
@ -168,15 +167,6 @@ impl<A, T: Iterator<A>> IteratorUtil<A> for T {
}
}
// Get first elemet of an iterator.
#[inline(always)]
fn first(&mut self) -> A {
match self.next() {
Some(x) => x ,
None => fail!("cannot get first element")
}
}
// Get last element of an iterator.
//
// If the iterator have an infinite length, this method won't return.
@ -700,20 +690,6 @@ mod tests {
v.iter().nth(5);
}
#[test]
fn test_iterator_first() {
let v = &[0, 1, 2, 3, 4];
assert_eq!(v.iter().first(), &0);
assert_eq!(v.slice(2, 5).iter().first(), &2);
}
#[test]
#[should_fail]
fn test_iterator_first_fail() {
let v: &[uint] = &[];
v.iter().first();
}
#[test]
fn test_iterator_last() {
let v = &[0, 1, 2, 3, 4];