exception Empty
Raised when
Queue.take
orQueue.peek
is applied to an empty queue.
val create : unit -> 'a t
Return a new queue, initially empty.
val add : 'a -> 'a t -> unit
add x q
adds the elementx
at the end of the queueq
.
val push : 'a -> 'a t -> unit
push
is a synonym foradd
.
val take : 'a t -> 'a
take q
removes and returns the first element in queueq
, or raisesEmpty
if the queue is empty.
val take_opt : 'a t -> 'a option
take_opt q
removes and returns the first element in queueq
, or returnsNone
if the queue is empty.- since
- 4.08
val pop : 'a t -> 'a
pop
is a synonym fortake
.
val peek : 'a t -> 'a
peek q
returns the first element in queueq
, without removing it from the queue, or raisesEmpty
if the queue is empty.
val peek_opt : 'a t -> 'a option
peek_opt q
returns the first element in queueq
, without removing it from the queue, or returnsNone
if the queue is empty.- since
- 4.08
val top : 'a t -> 'a
top
is a synonym forpeek
.
val clear : 'a t -> unit
Discard all elements from a queue.
val is_empty : 'a t -> bool
Return
true
if the given queue is empty,false
otherwise.
val length : 'a t -> int
Return the number of elements in a queue.
val iter : ('a -> unit) -> 'a t -> unit
iter f q
appliesf
in turn to all elements ofq
, from the least recently entered to the most recently entered. The queue itself is unchanged.
val fold : ('b -> 'a -> 'b) -> 'b -> 'a t -> 'b
fold f accu q
is equivalent toList.fold_left f accu l
, wherel
is the list ofq
's elements. The queue remains unchanged.
val transfer : 'a t -> 'a t -> unit
transfer q1 q2
adds all ofq1
's elements at the end of the queueq2
, then clearsq1
. It is equivalent to the sequenceiter (fun x -> add x q2) q1; clear q1
, but runs in constant time.
Iterators
val to_seq : 'a t -> 'a Stdlib.Seq.t
Iterate on the queue, in front-to-back order. The behavior is not defined if the queue is modified during the iteration.
- since
- 4.07
val add_seq : 'a t -> 'a Stdlib.Seq.t -> unit
Add the elements from the generator to the end of the queue
- since
- 4.07
val of_seq : 'a Stdlib.Seq.t -> 'a t
Create a queue from the generator
- since
- 4.07