.TH "Stdlib.Queue" 3o 2023-09-18 OCamldoc "OCaml library" .SH NAME Stdlib.Queue \- no description .SH Module Module Stdlib.Queue .SH Documentation .sp Module .BI "Queue" : .B (module Stdlib__Queue) .sp .sp .sp .sp .I type .B 'a .I t .sp The type of queues containing elements of type .ft B \&'a .ft R \&. .sp .I exception Empty .sp Raised when .ft B Queue\&.take .ft R or .ft B Queue\&.peek .ft R is applied to an empty queue\&. .sp .I val create : .B unit -> 'a t .sp Return a new queue, initially empty\&. .sp .I val add : .B 'a -> 'a t -> unit .sp .ft B add x q .ft R adds the element .ft B x .ft R at the end of the queue .ft B q .ft R \&. .sp .I val push : .B 'a -> 'a t -> unit .sp .ft B push .ft R is a synonym for .ft B add .ft R \&. .sp .I val take : .B 'a t -> 'a .sp .ft B take q .ft R removes and returns the first element in queue .ft B q .ft R , or raises .ft B Queue\&.Empty .ft R if the queue is empty\&. .sp .I val take_opt : .B 'a t -> 'a option .sp .ft B take_opt q .ft R removes and returns the first element in queue .ft B q .ft R , or returns .ft B None .ft R if the queue is empty\&. .sp .B "Since" 4.08 .sp .I val pop : .B 'a t -> 'a .sp .ft B pop .ft R is a synonym for .ft B take .ft R \&. .sp .I val peek : .B 'a t -> 'a .sp .ft B peek q .ft R returns the first element in queue .ft B q .ft R , without removing it from the queue, or raises .ft B Queue\&.Empty .ft R if the queue is empty\&. .sp .I val peek_opt : .B 'a t -> 'a option .sp .ft B peek_opt q .ft R returns the first element in queue .ft B q .ft R , without removing it from the queue, or returns .ft B None .ft R if the queue is empty\&. .sp .B "Since" 4.08 .sp .I val top : .B 'a t -> 'a .sp .ft B top .ft R is a synonym for .ft B peek .ft R \&. .sp .I val clear : .B 'a t -> unit .sp Discard all elements from a queue\&. .sp .I val copy : .B 'a t -> 'a t .sp Return a copy of the given queue\&. .sp .I val is_empty : .B 'a t -> bool .sp Return .ft B true .ft R if the given queue is empty, .ft B false .ft R otherwise\&. .sp .I val length : .B 'a t -> int .sp Return the number of elements in a queue\&. .sp .I val iter : .B ('a -> unit) -> 'a t -> unit .sp .ft B iter f q .ft R applies .ft B f .ft R in turn to all elements of .ft B q .ft R , from the least recently entered to the most recently entered\&. The queue itself is unchanged\&. .sp .I val fold : .B ('b -> 'a -> 'b) -> 'b -> 'a t -> 'b .sp .ft B fold f accu q .ft R is equivalent to .ft B List\&.fold_left f accu l .ft R , where .ft B l .ft R is the list of .ft B q .ft R \&'s elements\&. The queue remains unchanged\&. .sp .I val transfer : .B 'a t -> 'a t -> unit .sp .ft B transfer q1 q2 .ft R adds all of .ft B q1 .ft R \&'s elements at the end of the queue .ft B q2 .ft R , then clears .ft B q1 .ft R \&. It is equivalent to the sequence .ft B iter (fun x \-> add x q2) q1; clear q1 .ft R , but runs in constant time\&. .sp .PP .SS Iterators .PP .I val to_seq : .B 'a t -> 'a Seq.t .sp Iterate on the queue, in front\-to\-back order\&. The behavior is not specified if the queue is modified during the iteration\&. .sp .B "Since" 4.07 .sp .I val add_seq : .B 'a t -> 'a Seq.t -> unit .sp Add the elements from a sequence to the end of the queue\&. .sp .B "Since" 4.07 .sp .I val of_seq : .B 'a Seq.t -> 'a t .sp Create a queue from a sequence\&. .sp .B "Since" 4.07 .sp