Skip to content


final class List<Type> < Object

Doubly-linked list. Beyond its typical uses, because List is a recursive data structure, it provides reasonably good sharing under Birch's lazy deep clone mechanism, although not as good as Stack and Queue, as they are singly-linked.


Long lists (length in the tens of thousands) can cause a segfault on destruction due to stack overflow. Possible solutions are:

  1. Use Vector instead.
  2. Remove items one-by-one before the List object goes out of scope (with e.g. popBack()).
  3. Increase the stack size with ulimit or similar.

Member Functions

Name Description
size Number of elements.
empty Is this empty?
clear Clear all elements.
front Get the first element.
back Get the last element.
get Get an element.
set Set an element.
pushFront Insert a new element at the start.
pushBack Insert a new element at the end.
popFront Remove the first element.
popBack Remove the last element.
insert Insert a new element.
erase Erase an element.
begin First node, if any.
end Last node, if any.
getNode Get a node.

Member Fibers

Name Description
walk Forward iteration.

Member Function Details


function back() -> Type

Get the last element.


function begin() -> ListNode<Type>?

First node, if any. This can be used to maintain a bidirectional iterator over the container.


function clear()

Clear all elements.


function empty() -> Boolean

Is this empty?


function end() -> ListNode<Type>?

Last node, if any. This can be used to maintain a bidirectional iterator over the container.


function erase(i:Integer)

Erase an element.

  • i: Position.


function front() -> Type

Get the first element.


function get(i:Integer) -> Type

Get an element.

  • i: Position.


function getNode(i:Integer) -> ListNode<Type>

Get a node.

  • i: Position.


function insert(i:Integer, x:Type)

Insert a new element.

  • i: Position.
  • x: Value.

Inserts the new element immediately before the current element at position i. To insert at the end of the container, use a position that is one more than the current size, or pushBack().


function popBack()

Remove the last element.


function popFront()

Remove the first element.


function pushBack(x:Type)

Insert a new element at the end.

  • x: Value.


function pushFront(x:Type)

Insert a new element at the start.

  • x: Value.


function set(i:Integer, x:Type)

Set an element.

  • i: Position.
  • x: Value.


function size() -> Integer

Number of elements.

Member Fiber Details


fiber walk() -> Type!

Forward iteration.

Return: a fiber object that yields each element in forward order.