Method in collections::list · List coil-stdlib

List::push_front

pub fn push_front(T v)
Import
use collections::list::{List};
Source: src/collections/list.hy

Adds v at the front. Constant time.

Called on a List value as value.push_front(…).

Parameters#

NameType
vT

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: Returns true when the list has no values.
  • List::push_back: Adds v at the back.
  • List::peek_front: Returns the front value without removing it, or None when the list is empty.
  • List::pop_front: Removes and returns the front value, or None when the list is empty.
  • List::pop_back: Removes and returns the back value, or None when the list is empty.
↑ ↓ navigate ↵ open