module Core_stack:Core_stack is a replacement for OCaml's standard Stack module that follows Core idioms and adds some functions.sig..end
Differences from the standard module:
pop and top return an option rather than raise Empty.
iter takes a labeled argument.
push takes the stack argument first.
Core_stack uses same implementation as the OCaml library. It is a
reimplementation rather than a wrapper to enable direct implementations
of some functions (e.g. fold) that cannot be easily implemented given
the functions provided by OCaml's Stack module.
exception Empty
type 'a t
include Binable.S1
include Sexpable.S1
include Container.S1
to_list and to_array returns the elements in order from the top of
the stack to the bottom.val invariant : 'a t -> unitval create : unit -> 'a tcreate () returns an empty stack.val push : 'a t -> 'a -> unitpush t x adds x to the top of stack t.val pop : 'a t -> 'a optionpop t returns None if t is empty, otherwise it returns Some x where
x is the top of t and removes x from the top of t.val pop_exn : 'a t -> 'apop_exn t removes and returns the top element of t, raising Empty if
t is empty.val top : 'a t -> 'a optiontop t returns None if t is empty, otherwise it returns Some x where
x is the top of t.val top_exn : 'a t -> 'atop_exn t returns the top element of t, raising Empty if t is empty.val clear : 'a t -> unitclear t discards all elements from t.val copy : 'a t -> 'a tcopy t returns a copy of t.val until_empty : 'a t -> ('a -> unit) -> unituntil_empty t f repeatedly pops an element v off of t and runs f v
until t becomes empty. It is fine if f adds more elements to t.