From a9c465ce1f1caaae58a31c57f665217ee58bb876 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Sat, 18 May 2013 04:20:01 -0400 Subject: [PATCH] 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 --- src/libcore/iterator.rs | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/src/libcore/iterator.rs b/src/libcore/iterator.rs index 588bd0bde534..68281526e6f9 100644 --- a/src/libcore/iterator.rs +++ b/src/libcore/iterator.rs @@ -49,7 +49,6 @@ pub trait IteratorUtil { 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(&mut self, start: B, f: &fn(B, A) -> B) -> B; fn count(&mut self) -> uint; @@ -168,15 +167,6 @@ impl> IteratorUtil 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];