Skip to content

Commit d33ad98

Browse files
committed
---
yaml --- r: 149626 b: refs/heads/try2 c: 4da6d04 h: refs/heads/master v: v3
1 parent 61e3c27 commit d33ad98

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
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: 1c27c90119b7e55ce160f39543874b166db7eae6
8+
refs/heads/try2: 4da6d041c268d58654d54b317288c940e5c623fd
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 & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,12 @@ impl<T:'static + Clone> List<T> {
105105
}
106106
}
107107
}
108-
}
109108

110-
/*
111-
/// Push one element into the front of a list, returning a new list
112-
/// THIS VERSION DOESN'T ACTUALLY WORK
113-
fn push<T:Clone>(ll: &mut @list<T>, vv: T) {
114-
ll = &mut @cons(vv, *ll)
109+
/// Push one element into the front of a list, returning a new list
110+
pub fn unshift(&self, element: T) -> List<T> {
111+
Cons(element, @(self.clone()))
112+
}
115113
}
116-
*/
117114

118115
#[cfg(test)]
119116
mod tests {
@@ -228,4 +225,13 @@ mod tests {
228225
assert_eq!(List::from_vec([1, 2, 3, 4]),
229226
List::from_vec([1, 2]).append(List::from_vec([3, 4])));
230227
}
228+
229+
#[test]
230+
fn test_unshift() {
231+
let list = List::from_vec([1]);
232+
let new_list = list.unshift(0);
233+
assert_eq!(list.len(), 1u);
234+
assert_eq!(new_list.len(), 2u);
235+
assert_eq!(new_list, List::from_vec([0, 1]));
236+
}
231237
}

0 commit comments

Comments
 (0)