Support.PureStack
Persistent stack data structure.
type 'a t
Essentially a list, but it additioanlly tracks its length as items are added and removed.
val empty : 'a t
Constructs an empty stack.
val length : 'a t -> int
Gets the length of the stack in O(1).
O(1)
val to_list : 'a t -> 'a list
Converts the stack to a list.
val is_empty : 'a t -> bool
Decides whether a stack is empty.
val push : 'a -> 'a t -> 'a t
Pushes an item onto the stack.
val pop : 'a t -> ('a * 'a t) option
Pops an item from the stack.
val cut : int -> 'a t -> ('a list * 'a t) option
Tries to pop n items from a stack, yielding them in a list. The elements are collected in _reverse order_, so the old top of the stack is the last element of the returned list.
n