Module Sequence


module Sequence: sig .. end
Finite sequences.

To avoid unnecessary list reversals in some contexts (typically, successive list iterations performed in unrelated functions), this module defines a new type ('a t) that combines a list and a direction, and provides associated helper functions. This new type also contains the list's length. Users of this module should maintain the consistency accross values of type 'a t. In particular, (l, Backward, n) and ((List.rev l), Forward, n) denote the same finite sequence.



type direction =
| Forward
| Backward
type 'a t = 'a list * direction * int 
val print : (unit, Format.formatter, unit) format ->
(Format.formatter -> 'a -> unit) -> Format.formatter -> 'a t -> unit
val is_empty : 'a t -> bool
val length : 'a t -> int
val rev : 'a t -> 'a t
val forward : 'a t -> 'a t
val backward : 'a t -> 'a t
val map : ('a -> 'b) -> 'a t -> 'b t
map f s returns the sequence obtained by applying f on each element of s. Its implementation is based on List.rev_map.
val filter : ('a -> bool) -> 'a t -> 'a t
filter p s returns the sequence obtained from s by keeping only the elements satisfying p.
val to_array : 'a t -> 'a array
to_array s returns a fresh array containing the elements of s.
val of_array : 'a array -> 'a t
of_array a is equivalent to (Array.to_list a, Forward, Array.length a).