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 when Stack.pop or Stack.top is applied to an empty stack. 😭
  • val create : unit -> 'a t β€” return a new stack, initially empty. ✨
  • val push : 'a -> 'a t -> unit β€” push x s adds the element x at the top of stack s. πŸ’…
  • val pop : 'a t -> 'a β€” pop s removes and returns the topmost element in stack s, or raises Stack.Empty if the stack is empty. 🫢
  • val pop_opt : 'a t -> 'a option β€” pop_opt s removes and returns the topmost element in stack s, or returns None if the stack is empty. Since 4.08. πŸŽ€
  • val drop : 'a t -> unit β€” drop s removes the topmost element in stack s, or raises Stack.Empty if the stack is empty. Since 5.1. πŸ”₯
  • val top : 'a t -> 'a β€” top s returns the topmost element in stack s, or raises Stack.Empty if the stack is empty. πŸ‘‘
  • val top_opt : 'a t -> 'a option β€” top_opt s returns the topmost element in stack s, or None if 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 β€” return true if the given stack is empty, false otherwise. πŸ’œ
  • val length : 'a t -> int β€” return the number of elements in a stack. Time complexity O(1). ⭐
  • val iter : ('a -> unit) -> 'a t -> unit β€” iter f s applies f in turn to all elements of s, 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 s is (f (... (f (f accu x1) x2) ...) xn) where x1 is the top of the stack, x2 the second element, and xn the 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