Skip to content

Commit 0fff66d

Browse files
committed
---
yaml --- r: 149624 b: refs/heads/try2 c: 65f1993 h: refs/heads/master v: v3
1 parent 54e7f4c commit 0fff66d

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
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: fed034c402eb22b60fb9d7581e720bb0010dae65
8+
refs/heads/try2: 65f19932309f068e09c7472dc06b3e8856afb6fc
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: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ impl<T> List<T> {
6161
Cons(ref head, _) => Some(head)
6262
}
6363
}
64+
65+
/// Returns all but the first element of a list
66+
pub fn tail(&self) -> Option<@List<T>> {
67+
match *self {
68+
Nil => None,
69+
Cons(_, tail) => Some(tail)
70+
}
71+
}
6472
}
6573

6674
impl<T> Container for List<T> {
@@ -78,14 +86,6 @@ impl<T:Eq> List<T> {
7886
}
7987
}
8088

81-
/// Returns all but the first element of a list
82-
pub fn tail<T>(list: @List<T>) -> @List<T> {
83-
match *list {
84-
Cons(_, tail) => return tail,
85-
Nil => fail!("list empty")
86-
}
87-
}
88-
8989
/// Appends one list to another
9090
pub fn append<T:Clone + 'static>(list: @List<T>, other: @List<T>) -> @List<T> {
9191
match *list {
@@ -117,7 +117,7 @@ fn push<T:Clone>(ll: &mut @list<T>, vv: T) {
117117

118118
#[cfg(test)]
119119
mod tests {
120-
use list::{List, Nil, tail};
120+
use list::{List, Nil};
121121
use list;
122122

123123
#[test]
@@ -143,13 +143,13 @@ mod tests {
143143

144144
#[test]
145145
fn test_from_vec() {
146-
let list = @List::from_vec([0, 1, 2]);
146+
let list = List::from_vec([0, 1, 2]);
147147
assert_eq!(list.head().unwrap(), &0);
148148

149-
let mut tail = tail(list);
149+
let mut tail = list.tail().unwrap();
150150
assert_eq!(tail.head().unwrap(), &1);
151151

152-
tail = tail(tail);
152+
tail = tail.tail().unwrap();
153153
assert_eq!(tail.head().unwrap(), &2);
154154
}
155155

0 commit comments

Comments
 (0)