Skip to content

Commit 112a948

Browse files
committed
---
yaml --- r: 106478 b: refs/heads/try c: 197116d h: refs/heads/master v: v3
1 parent aaf5ff4 commit 112a948

File tree

2 files changed

+8
-26
lines changed

2 files changed

+8
-26
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: b8ef9fd9c9f642ce7b8aed82782a1ed745d08d64
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: b8601a3d8b91ad3b653d143307611f2f5c75617e
5-
refs/heads/try: d68190706448b5a1ca09be690f360c08a7a4f831
5+
refs/heads/try: 197116d7ce7862b21eac6af498a2726d7a1bc3d6
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/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)