Module Lwt_sequence


module Lwt_sequence: sig .. end
Mutable sequence of elements


A sequence is an object holding a list of elements which support the following operations:


type 'a t 
Type of a sequence holding values of type 'a
type 'a node 
Type of a node holding one value of type 'a in a sequence
exception Empty
Exception raised by take_* when the sequence is empty

Operation on nodes

val get : 'a node -> 'a
Returns the contents of a node
val set : 'a node -> 'a -> unit
Change the contents of a node
val remove : 'a node -> unit
Removes a node from the sequence it is part of. It does nothing if the node has already been removed.

Operations on sequence

val create : unit -> 'a t
create () creates a new empty sequence
val is_empty : 'a t -> bool
Returns true iff the given sequence is empty
val add_l : 'a -> 'a t -> 'a node
add_l x s adds x to the left of the sequence s
val add_r : 'a -> 'a t -> 'a node
add_l x s adds x to the right of the sequence s
val take_l : 'a t -> 'a
take_l x s remove and returns the leftmost element of s
Raises Empty if the sequence is empty
val take_r : 'a t -> 'a
take_l x s remove and returns the rightmost element of s
Raises Empty if the sequence is empty
val take_opt_l : 'a t -> 'a option
take_opt_l x s remove and returns Some x where x is the leftmost element of s or None if s is empty
val take_opt_r : 'a t -> 'a option
take_opt_l x s remove and returns Some x where x is the rightmost element of s or None if s is empty
val transfer_l : 'a t -> 'a t -> unit
transfer_l s1 s2 removes all elements of s1 and add them at the left of s2. This operation runs in constant time and space.
val transfer_r : 'a t -> 'a t -> unit
transfer_r s1 s2 removes all elements of s1 and add them at the right of s2. This operation runs in constant time and space.

Sequence transferal


Note: it is OK to remove nodes while traversing a sequence
val iter_l : ('a -> unit) -> 'a t -> unit
iter_l f s applies f on all elements of s starting from the left
val iter_r : ('a -> unit) -> 'a t -> unit
iter_l f s applies f on all elements of s starting from the right
val iter_node_l : ('a node -> unit) -> 'a t -> unit
iter_l f s applies f on all nodes of s starting from the left
val iter_node_r : ('a node -> unit) -> 'a t -> unit
iter_l f s applies f on all nodes of s starting from the right
val fold_l : ('a -> 'b -> 'b) -> 'a t -> 'b -> 'b
fold_l f s is:

        fold_l f s x = f en (... (f e2 (f e1 x)))
      

where to_list s = [e1; e2; ...; en]

val fold_r : ('a -> 'b -> 'b) -> 'a t -> 'b -> 'b
fold_r f s is:

        fold_r f s x = f e1 (f e2 (... (f en x)))
      

where to_list s = [e1; e2; ...; en]