about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno.d@partner.samsung.com>2014-02-24 22:40:57 -0400
committerBruno de Oliveira Abinader <bruno.d@partner.samsung.com>2014-02-27 08:35:46 -0400
commitd68190706448b5a1ca09be690f360c08a7a4f831 (patch)
treed7f329b0717ffb7edc9ff02b275db5d8b7d5cc96
parenta09a4b882d415ea764f58816b963de0203c4e9f0 (diff)
Removed list::find() in favor of iter().find()
-rw-r--r--src/libcollections/list.rs41
1 files changed, 11 insertions, 30 deletions
diff --git a/src/libcollections/list.rs b/src/libcollections/list.rs
index ce6084923f9..459b0a78a1e 100644
--- a/src/libcollections/list.rs
+++ b/src/libcollections/list.rs
@@ -54,26 +54,6 @@ impl<T> List<T> {
 }
 
 /**
- * Search for an element that matches a given predicate
- *
- * Apply function `f` to each element of `list`, starting from the first.
- * When function `f` returns true then an option containing the element
- * is returned. If `f` matches no elements then none is returned.
- */
-pub fn find<T:Clone>(list: @List<T>, f: |&T| -> bool) -> Option<T> {
-    let mut list = list;
-    loop {
-        list = match *list {
-          Cons(ref head, tail) => {
-            if f(head) { return Some((*head).clone()); }
-            tail
-          }
-          Nil => return None
-        }
-    };
-}
-
-/**
  * Returns true if a list contains an element that matches a given predicate
  *
  * Apply function `f` to each element of `list`, starting from the first.
@@ -196,8 +176,6 @@ mod tests {
     use list::{List, Nil, head, is_empty, tail};
     use list;
 
-    use std::option;
-
     #[test]
     fn test_iter() {
         let list = List::from_vec([0, 1, 2]);
@@ -254,18 +232,21 @@ mod tests {
 
     #[test]
     fn test_find_success() {
-        fn match_(i: &int) -> bool { return *i == 2; }
-        let list = @List::from_vec([0, 1, 2]);
-        assert_eq!(list::find(list, match_), option::Some(2));
+        fn match_(i: & &int) -> bool { **i == 2 }
+
+        let list = List::from_vec([0, 1, 2]);
+        assert_eq!(list.iter().find(match_).unwrap(), &2);
     }
 
     #[test]
     fn test_find_fail() {
-        fn match_(_i: &int) -> bool { return false; }
-        let list = @List::from_vec([0, 1, 2]);
-        let empty = @list::Nil::<int>;
-        assert_eq!(list::find(list, match_), option::None::<int>);
-        assert_eq!(list::find(empty, match_), option::None::<int>);
+        fn match_(_i: & &int) -> bool { false }
+
+        let empty = Nil::<int>;
+        assert_eq!(empty.iter().find(match_), None);
+
+        let list = List::from_vec([0, 1, 2]);
+        assert_eq!(list.iter().find(match_), None);
     }
 
     #[test]