Skip to content

Commit 197116d

Browse files
committed
Removed list::any() in favor of iter().any()
1 parent d681907 commit 197116d

File tree

1 file changed

+7
-25
lines changed

1 file changed

+7
-25
lines changed

src/libcollections/list.rs

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -53,26 +53,6 @@ impl<T> List<T> {
5353
}
5454
}
5555

56-
/**
57-
* Returns true if a list contains an element that matches a given predicate
58-
*
59-
* Apply function `f` to each element of `list`, starting from the first.
60-
* When function `f` returns true then it also returns true. If `f` matches no
61-
* elements then false is returned.
62-
*/
63-
pub fn any<T>(list: @List<T>, f: |&T| -> bool) -> bool {
64-
let mut list = list;
65-
loop {
66-
list = match *list {
67-
Cons(ref head, tail) => {
68-
if f(head) { return true; }
69-
tail
70-
}
71-
Nil => return false
72-
}
73-
};
74-
}
75-
7656
/// Returns true if a list contains an element with the given value
7757
pub fn has<T:Eq>(list: @List<T>, element: T) -> bool {
7858
let mut found = false;
@@ -251,11 +231,13 @@ mod tests {
251231

252232
#[test]
253233
fn test_any() {
254-
fn match_(i: &int) -> bool { return *i == 2; }
255-
let list = @List::from_vec([0, 1, 2]);
256-
let empty = @list::Nil::<int>;
257-
assert_eq!(list::any(list, match_), true);
258-
assert_eq!(list::any(empty, match_), false);
234+
fn match_(i: &int) -> bool { *i == 2 }
235+
236+
let empty = Nil::<int>;
237+
assert_eq!(empty.iter().any(match_), false);
238+
239+
let list = List::from_vec([0, 1, 2]);
240+
assert_eq!(list.iter().any(match_), true);
259241
}
260242

261243
#[test]

0 commit comments

Comments
 (0)