@@ -53,26 +53,6 @@ impl<T> List<T> {
53
53
}
54
54
}
55
55
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
-
76
56
/// Returns true if a list contains an element with the given value
77
57
pub fn has < T : Eq > ( list : @List < T > , element : T ) -> bool {
78
58
let mut found = false ;
@@ -251,11 +231,13 @@ mod tests {
251
231
252
232
#[ test]
253
233
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 ) ;
259
241
}
260
242
261
243
#[ test]
0 commit comments