List[A: A]

A doubly linked list.

class ref List[A: A] is
  Seq[A] ref

Implements


Constructors

create

new ref create(
  len: USize val = seq)
: List[A] ref^

Parameters

Returns


unit

new ref unit(
  a: A)
: List[A] ref^

Parameters

  • a: A

Returns


from

new ref from(
  seq: Array[A^] ref)
: List[A] ref^

Parameters

Returns


Public Functions

reserve

Do nothing, but be compatible with Seq.

fun ref reserve(
  len: USize val)
: None val

Parameters

Returns


size

Returns the number of items in the list.

fun box size()
: USize val

Returns


apply

Get the i-th element, raising an error if the index is out of bounds.

fun box apply(
  i: USize val = seq)
: this->A ?

Parameters

Returns

  • this->A ?

update

Change the i-th element, raising an error if the index is out of bounds. Returns the previous value, which may be None if the node has been popped but left on the list.

fun ref update(
  i: USize val,
  value: A)
: A^ ?

Parameters

Returns

  • A^ ?

index

Gets the i-th node, raising an error if the index is out of bounds.

fun box index(
  i: USize val)
: this->ListNode[A] ref ?

Parameters

Returns


remove

Remove the i-th node, raising an error if the index is out of bounds. The removed node is returned.

fun ref remove(
  i: USize val)
: ListNode[A] ref ?

Parameters

Returns


clear

Empties the list.

fun ref clear()
: None val

Returns


Get the head of the list.

fun box head()
: this->ListNode[A] ref ?

Returns


tail

Get the tail of the list.

fun box tail()
: this->ListNode[A] ref ?

Returns


prepend_node

Adds a node to the head of the list.

fun ref prepend_node(
  node: ListNode[A] ref)
: None val

Parameters

Returns


append_node

Adds a node to the tail of the list.

fun ref append_node(
  node: ListNode[A] ref)
: None val

Parameters

Returns


append_list

Remove all nodes from that and append them to this.

fun ref append_list(
  that: List[A] ref)
: None val

Parameters

Returns


prepend_list

Remove all nodes from that and prepend them to this.

fun ref prepend_list(
  that: List[A] ref)
: None val

Parameters

Returns


push

Adds a value to the tail of the list.

fun ref push(
  a: A)
: None val

Parameters

  • a: A

Returns


pop

Removes a value from the tail of the list.

fun ref pop()
: A^ ?

Returns

  • A^ ?

unshift

Adds a value to the head of the list.

fun ref unshift(
  a: A)
: None val

Parameters

  • a: A

Returns


shift

Removes a value from the head of the list.

fun ref shift()
: A^ ?

Returns

  • A^ ?

append

Append len elements from a sequence, starting from the given offset.

fun ref append(
  seq: (ReadSeq[A] box & ReadElement[A^] box),
  offset: USize val = seq,
  len: USize val = seq)
: None val

Parameters

Returns


concat

Add len iterated elements to the end of the list, starting from the given offset.

fun ref concat(
  iter: Iterator[A^] ref,
  offset: USize val = seq,
  len: USize val = seq)
: None val

Parameters

Returns


truncate

Truncate the list to the given length, discarding excess elements. If the list is already smaller than len, do nothing.

fun ref truncate(
  len: USize val)
: None val

Parameters

Returns


clone

Clone the list.

fun box clone()
: List[this->A!] ref^

Returns

  • List[this->A!] ref^

map[B: B]

Builds a new list by applying a function to every member of the list.

fun box map[B: B](
  f: {(this->A!): B^}[A, B] box)
: List[B] ref^

Parameters

  • f: {(this->A!): B^}[A, B] box

Returns


flat_map[B: B]

Builds a new list by applying a function to every member of the list and using the elements of the resulting lists.

fun box flat_map[B: B](
  f: {(this->A!): List[B]}[A, B] box)
: List[B] ref^

Parameters

  • f: {(this->A!): List[B]}[A, B] box

Returns


filter

Builds a new list with those elements that satisfy a provided predicate.

fun box filter(
  f: {(this->A!): Bool}[A] box)
: List[this->A!] ref^

Parameters

  • f: {(this->A!): Bool}[A] box

Returns

  • List[this->A!] ref^

fold[B: B]

Folds the elements of the list using the supplied function.

fun box fold[B: B](
  f: {(B!, this->A!): B^}[A, B] box,
  acc: B)
: B

Parameters

  • f: {(B!, this->A!): B^}[A, B] box
  • acc: B

Returns

  • B

every

Returns true if every element satisfies the provided predicate, false otherwise.

fun box every(
  f: {(this->A!): Bool}[A] box)
: Bool val

Parameters

  • f: {(this->A!): Bool}[A] box

Returns


exists

Returns true if at least one element satisfies the provided predicate, false otherwise.

fun box exists(
  f: {(this->A!): Bool}[A] box)
: Bool val

Parameters

  • f: {(this->A!): Bool}[A] box

Returns


partition

Builds a pair of lists, the first of which is made up of the elements satisfying the supplied predicate and the second of which is made up of those that do not.

fun box partition(
  f: {(this->A!): Bool}[A] box)
: (List[this->A!] ref^ , List[this->A!] ref^)

Parameters

  • f: {(this->A!): Bool}[A] box

Returns

  • (List[this->A!] ref^ , List[this->A!] ref^)

drop

Builds a list by dropping the first n elements.

fun box drop(
  n: USize val)
: List[this->A!] ref^

Parameters

Returns

  • List[this->A!] ref^

take

Builds a list of the first n elements.

fun box take(
  n: USize val)
: List[this->A!] ref

Parameters

Returns

  • List[this->A!] ref

take_while

Builds a list of elements satisfying the provided predicate until one does not.

fun box take_while(
  f: {(this->A!): Bool}[A] box)
: List[this->A!] ref^

Parameters

  • f: {(this->A!): Bool}[A] box

Returns

  • List[this->A!] ref^

reverse

Builds a new list by reversing the elements in the list.

fun box reverse()
: List[this->A!] ref^

Returns

  • List[this->A!] ref^

contains[optional B: (A & HasEq[A!] #read)]

Returns true if the list contains the provided element, false otherwise.

fun box contains[optional B: (A & HasEq[A!] #read)](
  a: box->B)
: Bool val

Parameters

  • a: box->B

Returns


nodes

Return an iterator on the nodes in the list.

fun box nodes()
: ListNodes[A, this->ListNode[A] ref] ref^

Returns


rnodes

Return an iterator on the nodes in the list.

fun box rnodes()
: ListNodes[A, this->ListNode[A] ref] ref^

Returns


values

Return an iterator on the values in the list.

fun box values()
: ListValues[A, this->ListNode[A] ref] ref^

Returns


rvalues

Return an iterator on the values in the list.

fun box rvalues()
: ListValues[A, this->ListNode[A] ref] ref^

Returns


Private Functions

_map[B: B]

Private helper for map, recursively working with ListNodes.

fun box _map[B: B](
  ln: this->ListNode[A] ref,
  f: {(this->A!): B^}[A, B] box,
  acc: List[B] ref)
: List[B] ref^

Parameters

  • ln: this->ListNode[A] ref
  • f: {(this->A!): B^}[A, B] box
  • acc: List[B] ref

Returns


_flat_map[B: B]

Private helper for flat_map, recursively working with ListNodes.

fun box _flat_map[B: B](
  ln: this->ListNode[A] ref,
  f: {(this->A!): List[B]}[A, B] box,
  acc: List[B] ref)
: List[B] ref^

Parameters

  • ln: this->ListNode[A] ref
  • f: {(this->A!): List[B]}[A, B] box
  • acc: List[B] ref

Returns


_filter

Private helper for filter, recursively working with ListNodes.

fun box _filter(
  ln: this->ListNode[A] ref,
  f: {(this->A!): Bool}[A] box,
  acc: List[this->A!] ref)
: List[this->A!] ref

Parameters

  • ln: this->ListNode[A] ref
  • f: {(this->A!): Bool}[A] box
  • acc: List[this->A!] ref

Returns

  • List[this->A!] ref

_fold[B: B]

Private helper for fold, recursively working with ListNodes.

fun box _fold[B: B](
  ln: this->ListNode[A] ref,
  f: {(B!, this->A!): B^}[A, B] box,
  acc: B)
: B

Parameters

  • ln: this->ListNode[A] ref
  • f: {(B!, this->A!): B^}[A, B] box
  • acc: B

Returns

  • B

_every

Private helper for every, recursively working with ListNodes.

fun box _every(
  ln: this->ListNode[A] ref,
  f: {(this->A!): Bool}[A] box)
: Bool val

Parameters

  • ln: this->ListNode[A] ref
  • f: {(this->A!): Bool}[A] box

Returns


_exists

Private helper for exists, recursively working with ListNodes.

fun box _exists(
  ln: this->ListNode[A] ref,
  f: {(this->A!): Bool}[A] box)
: Bool val

Parameters

  • ln: this->ListNode[A] ref
  • f: {(this->A!): Bool}[A] box

Returns


_reverse

Private helper for reverse, recursively working with ListNodes.

fun box _reverse(
  ln: this->ListNode[A] ref,
  acc: List[this->A!] ref)
: List[this->A!] ref^

Parameters

Returns

  • List[this->A!] ref^

_contains[optional B: (A & HasEq[A!] #read)]

Private helper for contains, recursively working with ListNodes.

fun box _contains[optional B: (A & HasEq[A!] #read)](
  ln: this->ListNode[A] ref,
  a: box->B)
: Bool val

Parameters

Returns


_increment

fun ref _increment()
: None val

Returns


_decrement

fun ref _decrement()
: None val

Returns


_set_head

fun ref _set_head(
  head': (ListNode[A] ref | None val))
: None val

Parameters

Returns


_set_tail

fun ref _set_tail(
  tail': (ListNode[A] ref | None val))
: None val

Parameters

Returns


_set_both

fun ref _set_both(
  node: ListNode[A] ref)
: None val

Parameters

Returns