1Stdlib.Stack(3)                  OCaml library                 Stdlib.Stack(3)
2
3
4

NAME

6       Stdlib.Stack - no description
7

Module

9       Module   Stdlib.Stack
10

Documentation

12       Module Stack
13        : (module Stdlib__Stack)
14
15
16
17
18
19
20
21
22
23       Unsynchronized accesses
24
25       Unsynchronized  accesses to a stack may lead to an invalid queue state.
26       Thus, concurrent accesses to stacks must be synchronized (for  instance
27       with a Mutex.t ).
28
29       type 'a t
30
31
32       The type of stacks containing elements of type 'a .
33
34
35
36       exception Empty
37
38
39       Raised when Stack.pop or Stack.top is applied to an empty stack.
40
41
42
43       val create : unit -> 'a t
44
45       Return a new stack, initially empty.
46
47
48
49       val push : 'a -> 'a t -> unit
50
51
52       push x s adds the element x at the top of stack s .
53
54
55
56       val pop : 'a t -> 'a
57
58
59       pop  s  removes  and returns the topmost element in stack s , or raises
60       Stack.Empty if the stack is empty.
61
62
63
64       val pop_opt : 'a t -> 'a option
65
66
67       pop_opt s removes and returns the topmost element in stack s ,  or  re‐
68       turns None if the stack is empty.
69
70
71       Since 4.08
72
73
74
75       val top : 'a t -> 'a
76
77
78       top s returns the topmost element in stack s , or raises Stack.Empty if
79       the stack is empty.
80
81
82
83       val top_opt : 'a t -> 'a option
84
85
86       top_opt s returns the topmost element in stack s , or None if the stack
87       is empty.
88
89
90       Since 4.08
91
92
93
94       val clear : 'a t -> unit
95
96       Discard all elements from a stack.
97
98
99
100       val copy : 'a t -> 'a t
101
102       Return a copy of the given stack.
103
104
105
106       val is_empty : 'a t -> bool
107
108       Return true if the given stack is empty, false otherwise.
109
110
111
112       val length : 'a t -> int
113
114       Return the number of elements in a stack. Time complexity O(1)
115
116
117
118       val iter : ('a -> unit) -> 'a t -> unit
119
120
121       iter  f  s applies f in turn to all elements of s , from the element at
122       the top of the stack to the element at the bottom  of  the  stack.  The
123       stack itself is unchanged.
124
125
126
127       val fold : ('b -> 'a -> 'b) -> 'b -> 'a t -> 'b
128
129
130       fold  f  accu  s is (f (... (f (f accu x1) x2) ...) xn) where x1 is the
131       top of the stack, x2 the second element, and xn the bottom element. The
132       stack is unchanged.
133
134
135       Since 4.03
136
137
138
139
140   Stacks and Sequences
141       val to_seq : 'a t -> 'a Seq.t
142
143       Iterate  on  the  stack, top to bottom.  It is safe to modify the stack
144       during iteration.
145
146
147       Since 4.07
148
149
150
151       val add_seq : 'a t -> 'a Seq.t -> unit
152
153       Add the elements from the sequence on the top of the stack.
154
155
156       Since 4.07
157
158
159
160       val of_seq : 'a Seq.t -> 'a t
161
162       Create a stack from the sequence.
163
164
165       Since 4.07
166
167
168
169
170
171OCamldoc                          2023-07-20                   Stdlib.Stack(3)
Impressum