Skip to content

Commit 4da6d04

Browse files
committed
Replaced list::push() with unshift() based on List<T>
1 parent 1c27c90 commit 4da6d04

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/libcollections/list.rs

+13-7
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)