Module Sequence
module Sequence:Finite sequences.sig..end
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'at ='a list * direction * int
val print : (unit, Format.formatter, unit) format ->
(Format.formatter -> 'a -> unit) -> Format.formatter -> 'a t -> unitval is_empty : 'a t -> boolval length : 'a t -> intval rev : 'a t -> 'a tval forward : 'a t -> 'a tval backward : 'a t -> 'a tval map : ('a -> 'b) -> 'a t -> 'b tmap 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 tfilter p s returns the sequence obtained from s by keeping only the
elements satisfying p.val to_array : 'a t -> 'a arrayto_array s returns a fresh array containing the elements of s.val of_array : 'a array -> 'a tof_array a is equivalent to (Array.to_list a, Forward, Array.length a).