Skip to content

Commit 9a62baf

Browse files
committed
---
yaml --- r: 149622 b: refs/heads/try2 c: 45fd63a h: refs/heads/master v: v3
1 parent e0fd4d6 commit 9a62baf

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 223f309fc3b0550803ec222bbb77f4ef129e915a
8+
refs/heads/try2: 45fd63a8b7b1fa0242d864f9592c05d06669b395
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libcollections/list.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,11 @@ impl<T> Container for List<T> {
6363
fn is_empty(&self) -> bool { match *self { Nil => true, _ => false } }
6464
}
6565

66-
/// Returns true if a list contains an element with the given value
67-
pub fn has<T:Eq>(list: @List<T>, element: T) -> bool {
68-
let mut found = false;
69-
each(list, |e| {
70-
if *e == element { found = true; false } else { true }
71-
});
72-
return found;
66+
impl<T:Eq> List<T> {
67+
/// Returns true if a list contains an element with the given value
68+
pub fn contains(&self, element: T) -> bool {
69+
self.iter().any(|list_element| *list_element == element)
70+
}
7371
}
7472

7573
/// Returns all but the first element of a list
@@ -208,13 +206,14 @@ mod tests {
208206
}
209207

210208
#[test]
211-
fn test_has() {
212-
let list = @List::from_vec([5, 8, 6]);
213-
let empty = @list::Nil::<int>;
214-
assert!((list::has(list, 5)));
215-
assert!((!list::has(list, 7)));
216-
assert!((list::has(list, 8)));
217-
assert!((!list::has(empty, 5)));
209+
fn test_contains() {
210+
let empty = Nil::<int>;
211+
assert!((!empty.contains(5)));
212+
213+
let list = List::from_vec([5, 8, 6]);
214+
assert!((list.contains(5)));
215+
assert!((!list.contains(7)));
216+
assert!((list.contains(8)));
218217
}
219218

220219
#[test]

0 commit comments

Comments
 (0)