Stdlib.Stack(3)
πΈ Stdlib.Stack(3) πΈ
okay so this is the Stdlib.Stack page from the OCaml library, bestie β manual name folded in right here so we didn't have to copy that crusty header line, periodt. β¨
π NAME π
Stdlib.Stack - no description. That's it. That's the whole name section. Mysterious main character energy, honestly π.
π§ Module π§
Module Stdlib.Stack
π Documentation π
Here's the module line exactly as the page gives it: Module Stack : (module Stdlib__Stack).
π¨ Unsynchronized accesses π¨
π¨ Warning, bestie: Unsynchronized accesses to a stack may lead to an invalid queue state. Thus, concurrent accesses to stacks must be synchronized (for instance with a Mutex.t). This is not a drill β the manual literally says it. π
type !'a tβ the type of stacks containing elements of type'a. π¦exception Emptyβ raised whenStack.poporStack.topis applied to an empty stack. πval create : unit -> 'a tβ return a new stack, initially empty. β¨val push : 'a -> 'a t -> unitβpush x sadds the elementxat the top of stacks. πval pop : 'a t -> 'aβpop sremoves and returns the topmost element in stacks, or raisesStack.Emptyif the stack is empty. π«Άval pop_opt : 'a t -> 'a optionβpop_opt sremoves and returns the topmost element in stacks, or returnsNoneif the stack is empty. Since 4.08. πval drop : 'a t -> unitβdrop sremoves the topmost element in stacks, or raisesStack.Emptyif the stack is empty. Since 5.1. π₯val top : 'a t -> 'aβtop sreturns the topmost element in stacks, or raisesStack.Emptyif the stack is empty. πval top_opt : 'a t -> 'a optionβtop_opt sreturns the topmost element in stacks, orNoneif the stack is empty. Since 4.08. πval clear : 'a t -> unitβ discard all elements from a stack. π§Ήval copy : 'a t -> 'a tβ return a copy of the given stack. π§val is_empty : 'a t -> boolβ returntrueif the given stack is empty,falseotherwise. πval length : 'a t -> intβ return the number of elements in a stack. Time complexityO(1). βval iter : ('a -> unit) -> 'a t -> unitβiter f sappliesfin turn to all elements ofs, from the element at the top of the stack to the element at the bottom of the stack. The stack itself is unchanged. πval fold : ('acc -> 'a -> 'acc) -> 'acc -> 'a t -> 'accβfold f accu sis(f (... (f (f accu x1) x2) ...) xn)wherex1is the top of the stack,x2the second element, andxnthe bottom element. The stack is unchanged. Since 4.03. πΈ
π¦ Stacks and Sequences π¦
val to_seq : 'a t -> 'a Seq.tβ iterate on the stack, top to bottom. It is safe to modify the stack during iteration. Since 4.07. β¨val add_seq : 'a t -> 'a Seq.t -> unitβ add the elements from the sequence on the top of the stack. Since 4.07. πval of_seq : 'a Seq.t -> 'a tβ create a stack from the sequence. Since 4.07. π¦
π«Ά That's the whole page, bestie. Signed off by OCamldoc, dated 2026-06-22, and filed under Stdlib.Stack(3). Mwah! π
π¦ where this page comes from
- arch rolling: ocaml 5.5.0-1 Β· LGPL2.1 AND custom: QPL-1.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms