Skip to content

Commit ea1cdec

Browse files
committed
---
yaml --- r: 102240 b: refs/heads/master c: 4da6d04 h: refs/heads/master v: v3
1 parent 6b83374 commit ea1cdec

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
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 1c27c90119b7e55ce160f39543874b166db7eae6
2+
refs/heads/master: 4da6d041c268d58654d54b317288c940e5c623fd
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 6e7f170fedd3c526a643c0b2d13863acd982be02
55
refs/heads/try: a97642026c18a624ff6ea01075dd9550f8ed07ff

trunk/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)