List::push_front
pub fn push_front(T v) Import
Source: use collections::list::{List}; src/collections/list.hy Adds v at the front. Constant time.
Called on a List value as value.push_front(…).
Parameters#
| Name | Type |
|---|---|
v | T |
Contracts#
Checked according to --contracts (see Contracts).
ensures self.len == old(self.len) + 1
Examples#
use collections::list::{List};
use tests::assert;
let xs: List<string> = List::new();
xs.push_front("b");
xs.push_front("a");
assert!((xs.peek_front() ?? "") == "a");
See also#
List: A singly-linked list with constant-time push and pop at the front.List::new: Creates an empty list.List::size: Returns the number of values.List::is_empty: Returnstruewhen the list has no values.List::push_back: Addsvat the back.List::peek_front: Returns the front value without removing it, orNonewhen the list is empty.List::pop_front: Removes and returns the front value, orNonewhen the list is empty.List::pop_back: Removes and returns the back value, orNonewhen the list is empty.