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