Skip to content

ListNode[A: A]

[Source]

A node in a list.

class ref ListNode[A: A]

Constructors

create

[Source]

Create a node. Initially, it is not in any list.

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

Parameters

  • item: (A | None val) = seq

Returns


Public Functions

apply

[Source]

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

fun box apply()
: this->A ?

Returns

  • this->A ?

update

[Source]

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

[Source]

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

fun ref pop()
: A^ ?

Returns

  • A^ ?

prepend

[Source]

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

[Source]

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

[Source]

Remove a node from a list.

fun ref remove()
: None val

Returns


has_prev

[Source]

Return true if there is a previous node.

fun box has_prev()
: Bool val

Returns


has_next

[Source]

Return true if there is a next node.

fun box has_next()
: Bool val

Returns


prev

[Source]

Return the previous node.

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

Returns


next

[Source]

Return the next node.

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

Returns


Private Functions

_set_list

[Source]

Make this node the only node on the given list.

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

Parameters

Returns