Skip to content

Commit 02dba8f

Browse files
committed
---
yaml --- r: 102234 b: refs/heads/master c: a14d72d h: refs/heads/master v: v3
1 parent 760977f commit 02dba8f

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: e589fcffcc8da46b5949d15284a466d9ed27a003
2+
refs/heads/master: a14d72d49e4d87b970f899a761dbdfce63239b79
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 6e7f170fedd3c526a643c0b2d13863acd982be02
55
refs/heads/try: a97642026c18a624ff6ea01075dd9550f8ed07ff

trunk/src/libcollections/list.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ impl<T> List<T> {
5858
impl<T> Container for List<T> {
5959
/// Returns the length of a list
6060
fn len(&self) -> uint { self.iter().len() }
61+
62+
/// Returns true if the list is empty
63+
fn is_empty(&self) -> bool { match *self { Nil => true, _ => false } }
6164
}
6265

6366
/// Returns true if a list contains an element with the given value
@@ -69,14 +72,6 @@ pub fn has<T:Eq>(list: @List<T>, element: T) -> bool {
6972
return found;
7073
}
7174

72-
/// Returns true if the list is empty
73-
pub fn is_empty<T>(list: @List<T>) -> bool {
74-
match *list {
75-
Nil => true,
76-
_ => false
77-
}
78-
}
79-
8075
/// Returns all but the first element of a list
8176
pub fn tail<T>(list: @List<T>) -> @List<T> {
8277
match *list {
@@ -153,7 +148,7 @@ pub fn each<T>(list: @List<T>, f: |&T| -> bool) -> bool {
153148

154149
#[cfg(test)]
155150
mod tests {
156-
use list::{List, Nil, head, is_empty, tail};
151+
use list::{List, Nil, head, tail};
157152
use list;
158153

159154
#[test]
@@ -168,13 +163,13 @@ mod tests {
168163

169164
#[test]
170165
fn test_is_empty() {
171-
let empty : @list::List<int> = @List::from_vec([]);
172-
let full1 = @List::from_vec([1]);
173-
let full2 = @List::from_vec(['r', 'u']);
166+
let empty : list::List<int> = List::from_vec([]);
167+
let full1 = List::from_vec([1]);
168+
let full2 = List::from_vec(['r', 'u']);
174169

175-
assert!(is_empty(empty));
176-
assert!(!is_empty(full1));
177-
assert!(!is_empty(full2));
170+
assert!(empty.is_empty());
171+
assert!(!full1.is_empty());
172+
assert!(!full2.is_empty());
178173
}
179174

180175
#[test]

trunk/src/test/run-pass/non-boolean-pure-fns.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
extern crate collections;
1616

17-
use collections::list::{List, Cons, Nil, head, is_empty};
17+
use collections::list::{List, Cons, Nil, head};
1818

1919
fn pure_length_go<T:Clone>(ls: @List<T>, acc: uint) -> uint {
2020
match *ls { Nil => { acc } Cons(_, tl) => { pure_length_go(tl, acc + 1u) } }
@@ -25,7 +25,7 @@ fn pure_length<T:Clone>(ls: @List<T>) -> uint { pure_length_go(ls, 0u) }
2525
fn nonempty_list<T:Clone>(ls: @List<T>) -> bool { pure_length(ls) > 0u }
2626

2727
fn safe_head<T:Clone>(ls: @List<T>) -> T {
28-
assert!(!is_empty(ls));
28+
assert!(!ls.is_empty());
2929
return head(ls);
3030
}
3131

0 commit comments

Comments
 (0)