ListNode[A: A]

A node in a list.

class ref ListNode[A: A]

Constructors

create

new ref create(
  item: (A | None val) = seq)
: ListNode[A] ref^

Parameters

  • item: (A | None val) = seq

Returns


Public Functions

apply

Return the item, if we have one, otherwise raise an error.

fun box apply()
: this->A ?

Returns

  • this->A ?

update

Replace the item and return the previous one. Raise an error if we have no previous value.

fun ref update(
  value: (A | None val))
: A^ ?

Parameters

  • value: (A | None val)

Returns

  • A^ ?

pop

Remove the item from the node, if we have one, otherwise raise an error.

fun ref pop()
: A^ ?

Returns

  • A^ ?

prepend

Prepend a node to this one. If that is already in a list, it is removed before it is prepended. Returns true if that was removed from another list.

fun ref prepend(
  that: ListNode[A] ref)
: Bool val

Parameters

Returns


append

Append a node to this one. If that is already in a list, it is removed before it is appended. Returns true if that was removed from another list.

fun ref append(
  that: ListNode[A] ref)
: Bool val

Parameters

Returns


remove

Remove a node from a list.

fun ref remove()
: None val

Returns


has_prev

Return true if there is a previous node.

fun box has_prev()
: Bool val

Returns


has_next

Return true if there is a next node.

fun box has_next()
: Bool val

Returns


prev

Return the previous node.

fun box prev()
: (this->ListNode[A] ref | None val)

Returns


next

Return the next node.

fun box next()
: (this->ListNode[A] ref | None val)

Returns


Private Functions

_set_list

Make this node the only node on the given list.

fun ref _set_list(
  list: List[A] ref)
: ListNode[A] ref^

Parameters

Returns