module SequenceLabels:sig..end
Version of Sequence with labels
Since 0.5.5
type'at =('a -> unit) -> unit
'a. If you give it a function 'a -> unit
it will be applied to every element of the sequence successively.type'asequence ='a t
type('a, 'b)t2 =('a -> 'b -> unit) -> unit
'a and 'b.type'aequal ='a -> 'a -> bool
type'ahash ='a -> int
val from_iter : (('a -> unit) -> unit) -> 'a tval from_fun : (unit -> 'a option) -> 'a tSequenceLabels.persistent if needed!val empty : 'a tval singleton : 'a -> 'a tval doubleton : 'a -> 'a -> 'a tval init : f:(int -> 'a) -> 'a tinit f is the infinite sequence f 0; f 1; f 2; ….val cons : 'a -> 'a t -> 'a tcons x l yields x, then yields from l.
Same as append (singleton x) lval snoc : 'a t -> 'a -> 'a t
val return : 'a -> 'a tSequenceLabels.singletonval pure : 'a -> 'a tSequenceLabels.singletonval repeat : 'a -> 'a tSequenceLabels.take and the likes if you iterate on it.val iterate : ('a -> 'a) -> 'a -> 'a titerate f x is the infinite sequence x, f(x), f(f(x)), ...val forever : (unit -> 'b) -> 'b tSequenceLabels.take and SequenceLabels.persistent.val cycle : 'a t -> 'a tSequenceLabels.take not to loop
forever.val iter : f:('a -> unit) -> 'a t -> unititer f seq is just seq f.val iteri : f:(int -> 'a -> unit) -> 'a t -> unitval fold : f:('a -> 'b -> 'a) -> init:'a -> 'b t -> 'aval foldi : f:('a -> int -> 'b -> 'a) -> init:'a -> 'b t -> 'aval fold_map : f:('acc -> 'a -> 'acc * 'b) ->
init:'acc -> 'a t -> 'b tfold_map f acc l is like SequenceLabels.map, but it carries some state as in
SequenceLabels.fold. The state is not returned, it is just used to thread some
information to the map function.val fold_filter_map : f:('acc -> 'a -> 'acc * 'b option) ->
init:'acc -> 'a t -> 'b tfold_filter_map f acc l is a SequenceLabels.fold_map-like function, but the
function can choose to skip an element by retuning None.val map : f:('a -> 'b) -> 'a t -> 'b tval mapi : f:(int -> 'a -> 'b) -> 'a t -> 'b tval map_by_2 : f:('a -> 'a -> 'a) -> 'a t -> 'a tval for_all : f:('a -> bool) -> 'a t -> boolval exists : f:('a -> bool) -> 'a t -> boolval mem : ?eq:('a -> 'a -> bool) -> x:'a -> 'a t -> booleq : the equality predicate to use (default (=))val find : ('a -> 'b option) -> 'a t -> 'b optionNoneval find_map : f:('a -> 'b option) -> 'a t -> 'b option
val findi : f:(int -> 'a -> 'b option) -> 'a t -> 'b option
val find_mapi : f:(int -> 'a -> 'b option) -> 'a t -> 'b option
val find_pred : f:('a -> bool) -> 'a t -> 'a optionfind_pred p l finds the first element of l that satisfies p,
or returns None if no element satisfies pval find_pred_exn : f:('a -> bool) -> 'a t -> 'a
val length : 'a t -> intval is_empty : 'a t -> boolval filter : f:('a -> bool) -> 'a t -> 'a tval append : 'a t -> 'a t -> 'a tval append_l : 'a t list -> 'a tval concat : 'a t t -> 'a tval flatten : 'a t t -> 'a tSequenceLabels.concatval flat_map : f:('a -> 'b t) -> 'a t -> 'b tflatMap with a more explicit nameval flat_map_l : f:('a -> 'b list) -> 'a t -> 'b t
val filter_map : f:('a -> 'b option) -> 'a t -> 'b tfmap with a more explicit nameval filter_mapi : f:(int -> 'a -> 'b option) -> 'a t -> 'b tNone elementsval seq_list : 'a t list -> 'a list tseq_list l returns all the ways to pick one element in each sub-sequence
in l. Assumes the sub-sequences can be iterated on several times.val seq_list_map : f:('a -> 'b t) -> 'a list -> 'b list t
val intersperse : x:'a -> 'a t -> 'a tval persistent : 'a t -> 'a tval persistent_lazy : 'a t -> 'a tSequenceLabels.persistent. When calling persistent_lazy s,
a new sequence s' is immediately returned (without actually consuming
s) in constant time; the first time s' is iterated on,
it also consumes s and caches its content into a inner data
structure that will back s' for future iterations.
warning: on the first traversal of s', if the traversal
is interrupted prematurely (SequenceLabels.take, etc.) then s' will not be
memorized, and the next call to s' will traverse s again.
val sort : ?cmp:('a -> 'a -> int) -> 'a t -> 'a tval sort_uniq : ?cmp:('a -> 'a -> int) -> 'a t -> 'a tsortval sorted : ?cmp:('a -> 'a -> int) -> 'a t -> bool
val group_succ_by : ?eq:('a -> 'a -> bool) -> 'a t -> 'a list tgroup.val group_by : ?hash:('a -> int) ->
?eq:('a -> 'a -> bool) -> 'a t -> 'a list tx and y, if eq x y then hash x=hash y must hold.val count : ?hash:('a -> int) ->
?eq:('a -> 'a -> bool) -> 'a t -> ('a * int) tgroup_by seq |> map (fun l->List.hd l, List.length l)val uniq : ?eq:('a -> 'a -> bool) -> 'a t -> 'a tfun seq -> map List.hd (group seq).val product : 'a t -> 'b t -> ('a * 'b) tproduct a b,
the caller MUST ensure that b can be traversed as many times
as required (several times), possibly by calling SequenceLabels.persistent on it
beforehand.val diagonal_l : 'a list -> ('a * 'a) tdiagonal l will
return the sequence of all List.nth i l, List.nth j l if i < j.val diagonal : 'a t -> ('a * 'a) tval product2 : 'a t -> 'b t -> ('a, 'b) t2
val join : join_row:('a -> 'b -> 'c option) ->
'a t -> 'b t -> 'c tjoin ~join_row a b combines every element of a with every
element of b using join_row. If join_row returns None, then
the two elements do not combine. Assume that b allows for multiple
iterations.val join_by : ?eq:'key equal ->
?hash:'key hash ->
('a -> 'key) ->
('b -> 'key) ->
merge:('key -> 'a -> 'b -> 'c option) ->
'a t -> 'b t -> 'c tjoin key1 key2 ~merge is a binary operation
that takes two sequences a and b, projects their
elements resp. with key1 and key2, and combine
values (x,y) from (a,b) with the same key
using merge. If merge returns None, the combination
of values is discarded.
precondition: for any x and y, if eq x y then hash x=hash y must hold.val join_all_by : ?eq:'key equal ->
?hash:'key hash ->
('a -> 'key) ->
('b -> 'key) ->
merge:('key -> 'a list -> 'b list -> 'c option) ->
'a t -> 'b t -> 'c tjoin_all_by key1 key2 ~merge is a binary operation
that takes two sequences a and b, projects their
elements resp. with key1 and key2, and, for each key k
occurring in at least one of them:l1 of elements of a that map to kl2 of elements of b that map to kmerge k l1 l2. If merge returns None, the combination
of values is discarded, otherwise it returns Some c
and c is inserted in the result.val group_join_by : ?eq:'a equal ->
?hash:'a hash ->
('b -> 'a) ->
'a t -> 'b t -> ('a * 'b list) tgroup_join_by key2 associates to every element x of
the first sequence, all the elements y of the second
sequence such that eq x (key y). Elements of the first
sequences without corresponding values in the second one
are mapped to []
precondition: for any x and y, if eq x y then hash x=hash y must hold.val inter : ?eq:'a equal ->
?hash:'a hash ->
'a t -> 'a t -> 'a tx and y, if eq x y then hash x=hash y must hold.val union : ?eq:'a equal ->
?hash:'a hash ->
'a t -> 'a t -> 'a tx and y, if eq x y then hash x=hash y must hold.val diff : ?eq:'a equal ->
?hash:'a hash ->
'a t -> 'a t -> 'a tval subset : ?eq:'a equal ->
?hash:'a hash ->
'a t -> 'a t -> boolsubset a b returns true if all elements of a belong to b. Eager.
precondition: for any x and y, if eq x y then hash x=hash y must hold.val unfoldr : ('b -> ('a * 'b) option) -> 'b -> 'a tunfoldr f b will apply f to b. If it
yields Some (x,b') then x is returned
and unfoldr recurses with b'.val scan : ('b -> 'a -> 'b) -> 'b -> 'a t -> 'b tval max : ?lt:('a -> 'a -> bool) -> 'a t -> 'a optionm where m is the maximal
element otherwiseval max_exn : ?lt:('a -> 'a -> bool) -> 'a t -> 'a
val min : ?lt:('a -> 'a -> bool) -> 'a t -> 'a optionSequenceLabels.max for more details.val min_exn : ?lt:('a -> 'a -> bool) -> 'a t -> 'a
val sum : int t -> intval sumf : float t -> floatval head : 'a t -> 'a optionNoneval head_exn : 'a t -> 'aInvalid_argument if the sequence is emptyval take : int -> 'a t -> 'a tn elements from the sequence. Works on infinite
sequences.val take_while : f:('a -> bool) -> 'a t -> 'a ts if the predicate is false for at
least one element of s.val fold_while : f:('a -> 'b -> 'a * [ `Continue | `Stop ]) ->
init:'a -> 'b t -> 'a('a, `Stop)val drop : int -> 'a t -> 'a tn first elements of the sequence. Lazy.val drop_while : f:('a -> bool) -> 'a t -> 'a tSequenceLabels.dropval rev : 'a t -> 'a tval empty2 : ('a, 'b) t2
val is_empty2 : ('a, 'b) t2 -> bool
val length2 : ('a, 'b) t2 -> int
val zip : ('a, 'b) t2 -> ('a * 'b) t
val unzip : ('a * 'b) t -> ('a, 'b) t2
val zip_i : 'a t -> (int, 'a) t2val fold2 : f:('c -> 'a -> 'b -> 'c) -> init:'c -> ('a, 'b) t2 -> 'c
val iter2 : f:('a -> 'b -> unit) -> ('a, 'b) t2 -> unit
val map2 : f:('a -> 'b -> 'c) -> ('a, 'b) t2 -> 'c t
val map2_2 : ('a -> 'b -> 'c) ->
('a -> 'b -> 'd) -> ('a, 'b) t2 -> ('c, 'd) t2map2_2 f g seq2 maps each x, y of seq2 into f x y, g x yval to_list : 'a t -> 'a listSequenceLabels.to_rev_list.val to_rev_list : 'a t -> 'a listSequenceLabels.to_list)val of_list : 'a list -> 'a t
val on_list : ('a t -> 'b t) -> 'a list -> 'b liston_list f l is equivalent to to_list @@ f @@ of_list l.val pair_with_idx : 'a t -> (int * 'a) t
val to_opt : 'a t -> 'a option
val to_array : 'a t -> 'a arrayval of_array : 'a array -> 'a t
val of_array_i : 'a array -> (int * 'a) tval of_array2 : 'a array -> (int, 'a) t2
val array_slice : 'a array -> int -> int -> 'a tarray_slice a i j Sequence of elements whose indexes range
from i to jval of_opt : 'a option -> 'a tval of_stream : 'a Stream.t -> 'a tval to_stream : 'a t -> 'a Stream.tval to_stack : 'a Stack.t -> 'a t -> unitval of_stack : 'a Stack.t -> 'a tStack.iter)val to_queue : 'a Queue.t -> 'a t -> unitval of_queue : 'a Queue.t -> 'a tval hashtbl_add : ('a, 'b) Hashtbl.t -> ('a * 'b) t -> unitval hashtbl_replace : ('a, 'b) Hashtbl.t -> ('a * 'b) t -> unitval to_hashtbl : ('a * 'b) t -> ('a, 'b) Hashtbl.tval to_hashtbl2 : ('a, 'b) t2 -> ('a, 'b) Hashtbl.tval of_hashtbl : ('a, 'b) Hashtbl.t -> ('a * 'b) tval of_hashtbl2 : ('a, 'b) Hashtbl.t -> ('a, 'b) t2val hashtbl_keys : ('a, 'b) Hashtbl.t -> 'a t
val hashtbl_values : ('a, 'b) Hashtbl.t -> 'b t
val of_str : string -> char t
val to_str : char t -> string
val concat_str : string t -> stringSequenceLabels.intersperse to add a separator.exception OneShotSequence
val of_in_channel : Pervasives.in_channel -> char tSequenceLabels.persistent.OneShotSequence when used more than once.val to_buffer : char t -> Buffer.t -> unitval int_range : start:int -> stop:int -> int tstart...stop by steps 1. Also see
(--) for an infix version.val int_range_dec : start:int -> stop:int -> int tstop...start by steps -1.
See (--^) for an infix versionval int_range_by : step:int -> start:int -> stop:int -> int tint_range_by ~step ~start:i ~stop:j is the range starting at i, including j,
where the difference between successive elements is step.
use a negative step for a decreasing sequence.Invalid_argument if step=0val bools : bool ttrue and falseval of_set : (module Set.S with type elt = 'a and type t = 'b) ->
'b -> 'a tval to_set : (module Set.S with type elt = 'a and type t = 'b) ->
'a t -> 'btype'agen =unit -> 'a option
type'aklist =unit -> [ `Cons of 'a * 'a klist | `Nil ]
val of_gen : 'a gen -> 'a tval to_gen : 'a t -> 'a genval of_klist : 'a klist -> 'a tval to_klist : 'a t -> 'a klistmodule Set:sig..end
module Map:sig..end
val random_int : int -> int tval random_bool : bool tval random_float : float -> float t
val random_array : 'a array -> 'a tval random_list : 'a list -> 'a tSequenceLabels.random_array.val shuffle : 'a t -> 'a tshuffle seq returns a perfect shuffle of seq.
Uses O(length seq) memory and time. Eager.val shuffle_buffer : n:int -> 'a t -> 'a tshuffle_buffer n seq returns a sequence of element of seq in random
order. The shuffling is not uniform. Uses O(n) memory.
The first n elements of the sequence are consumed immediately. The
rest is consumed lazily.
Since 0.7
val sample : n:int -> 'a t -> 'a arraysample n seq returns k samples of seq, with uniform probability.
It will consume the sequence and use O(n) memory.
It returns an array of size min (length seq) n.
Since 0.7
module Infix:sig..end
include SequenceLabels.Infix
val pp_seq : ?sep:string ->
(Format.formatter -> 'a -> unit) ->
Format.formatter -> 'a t -> unit'a, using the given pretty printer
to print each elements. An optional separator string can be provided.val pp_buf : ?sep:string ->
(Buffer.t -> 'a -> unit) -> Buffer.t -> 'a t -> unitval to_string : ?sep:string -> ('a -> string) -> 'a t -> stringVery basic interface to manipulate files as sequence of chunks/lines. The sequences take care of opening and closing files properly; every time one iterates over a sequence, the file is opened/closed again.
Example: copy a file "a" into file "b", removing blank lines:
Sequence.(IO.lines_of "a" |> filter (fun l-> l<> "") |> IO.write_lines "b");;
By chunks of 4096 bytes:
Sequence.IO.(chunks_of ~size:4096 "a" |> write_to "b");;
Read the lines of a file into a list:
Sequence.IO.lines "a" |> Sequence.to_list
module IO:sig..end