crow/col/stack.crow (source)

stack[t] record

(has non-public fields)

    Immutable stack type.
    Iteration functions move from the bottom to the top.

    new[t] t stack(...a t array)

    Stack containing the given elements.

    The first element of a goes on the bottom and the last element of a goes on the top.

    to[t] t stack(a t array)

    Stack containing the given elements.

    The first element of a goes on the bottom and the last element of a goes on the top.

    to[t] t array(a t stack)

    is-empty[t] bool(a t stack)

    true iff a.size == 0.

    ~[t] t stack(a t stack, b t)

    Appends an element to the stack.
    This is O(1).

    size[t] nat64(a t stack)

    Number of elements in the stack.
    This is O(1).

    peek[t] t?(a t stack)

    Top element.
    Returns an empty option iff a is empty.
    This is O(1).

    pop[t] (t stack, t) tuple2?(a t stack)

    Returns the top element of the a stacknd a new stack with all elements but the top.
    Returns an empty option iff a is empty.

    iterate[t] bool(a t stack, f mut bool(t))

    stack-iterator[t] record

    (has non-public fields)

      begin[t] t stack-iterator(a t stack)

      end[t] t stack-iterator(a t stack)

      prev[t] (t stack-iterator, t) tuple2?(a t stack-iterator)

      next[t] (t, t stack-iterator) tuple2?(a t stack-iterator)