Skip to content

Commit aaf5ff4

Browse files
committed
---
yaml --- r: 106477 b: refs/heads/try c: d681907 h: refs/heads/master i: 106475: d674e8b v: v3
1 parent 84a5626 commit aaf5ff4

File tree

2 files changed

+12
-31
lines changed

2 files changed

+12
-31
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: a09a4b882d415ea764f58816b963de0203c4e9f0
5+
refs/heads/try: d68190706448b5a1ca09be690f360c08a7a4f831
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: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -53,26 +53,6 @@ impl<T> List<T> {
5353
}
5454
}
5555

56-
/**
57-
* Search for 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 an option containing the element
61-
* is returned. If `f` matches no elements then none is returned.
62-
*/
63-
pub fn find<T:Clone>(list: @List<T>, f: |&T| -> bool) -> Option<T> {
64-
let mut list = list;
65-
loop {
66-
list = match *list {
67-
Cons(ref head, tail) => {
68-
if f(head) { return Some((*head).clone()); }
69-
tail
70-
}
71-
Nil => return None
72-
}
73-
};
74-
}
75-
7656
/**
7757
* Returns true if a list contains an element that matches a given predicate
7858
*
@@ -196,8 +176,6 @@ mod tests {
196176
use list::{List, Nil, head, is_empty, tail};
197177
use list;
198178

199-
use std::option;
200-
201179
#[test]
202180
fn test_iter() {
203181
let list = List::from_vec([0, 1, 2]);
@@ -254,18 +232,21 @@ mod tests {
254232

255233
#[test]
256234
fn test_find_success() {
257-
fn match_(i: &int) -> bool { return *i == 2; }
258-
let list = @List::from_vec([0, 1, 2]);
259-
assert_eq!(list::find(list, match_), option::Some(2));
235+
fn match_(i: & &int) -> bool { **i == 2 }
236+
237+
let list = List::from_vec([0, 1, 2]);
238+
assert_eq!(list.iter().find(match_).unwrap(), &2);
260239
}
261240

262241
#[test]
263242
fn test_find_fail() {
264-
fn match_(_i: &int) -> bool { return false; }
265-
let list = @List::from_vec([0, 1, 2]);
266-
let empty = @list::Nil::<int>;
267-
assert_eq!(list::find(list, match_), option::None::<int>);
268-
assert_eq!(list::find(empty, match_), option::None::<int>);
243+
fn match_(_i: & &int) -> bool { false }
244+
245+
let empty = Nil::<int>;
246+
assert_eq!(empty.iter().find(match_), None);
247+
248+
let list = List::from_vec([0, 1, 2]);
249+
assert_eq!(list.iter().find(match_), None);
269250
}
270251

271252
#[test]

0 commit comments

Comments
 (0)