module type S = Gen_intf.S
type 'a
t
val empty : 'a t
val singleton : 'a -> 'a t
val return : 'a -> 'a t
val repeat : 'a -> 'a t
val iterate : 'a -> ('a -> 'a) -> 'a t
iterate x f
is [x; f x; f (f x); f (f (f x)); ...]
val unfold : ('b -> ('a * 'b) option) -> 'b -> 'a t
Gen_intf.S.fold
, with a deconstructing operation. It keeps on
unfolding the 'b
value into a new 'b
, and a 'a
which is yielded,
until None
is returned.val init : ?limit:int -> (int -> 'a) -> 'a t
limit
is provided and is a positive int, iteration will
stop at the limit (excluded).
For instance init ~limit:4 id
will yield 0, 1, 2, and 3.
Note: those combinators, applied to generators (not restartable
generators) consume their argument. Sometimes they consume it lazily,
sometimes eagerly, but in any case once f gen
has been called (with f
a
combinator), gen
shouldn't be used anymore.
val is_empty : 'a t -> bool
val fold : ('b -> 'a -> 'b) -> 'b -> 'a t -> 'b
val reduce : ('a -> 'a -> 'a) -> 'a t -> 'a
Invalid_argument
on an empty genval scan : ('b -> 'a -> 'b) -> 'b -> 'a t -> 'b t
Gen_intf.S.fold
, but keeping successive values of the accumulator.
Consumes the generator.val unfold_scan : ('b -> 'a -> 'b * 'c) -> 'b -> 'a t -> 'c t
Gen_intf.S.unfold
and Gen_intf.S.scan
. The current state is combined with
the current element to produce a new state, and an output value
of type 'c.val iter : ('a -> unit) -> 'a t -> unit
val iteri : (int -> 'a -> unit) -> 'a t -> unit
val length : 'a t -> int
val map : ('a -> 'b) -> 'a t -> 'b t
val mapi : (int -> 'a -> 'b) -> 'a t -> 'b t
val fold_map : ('b -> 'a -> 'b) -> 'b -> 'a t -> 'b t
val append : 'a t -> 'a t -> 'a t
val flatten : 'a Gen_intf.gen t -> 'a t
val flat_map : ('a -> 'b Gen_intf.gen) -> 'a t -> 'b t
val mem : ?eq:('a -> 'a -> bool) -> 'a -> 'a t -> bool
val take : int -> 'a t -> 'a t
val drop : int -> 'a t -> 'a t
val nth : int -> 'a t -> 'a
Not_found
if the generator contains less than n
argumentsval take_nth : int -> 'a t -> 'a t
take_nth n g
returns every element of g
whose index
is a multiple of n
. For instance take_nth 2 (1--10) |> to_list
will return 1;3;5;7;9
val filter : ('a -> bool) -> 'a t -> 'a t
val take_while : ('a -> bool) -> 'a t -> 'a t
val fold_while : ('a -> 'b -> 'a * [ `Continue | `Stop ]) -> 'a -> 'b t -> 'a
'a, `Stop
) is indicated by the accumulator.val drop_while : ('a -> bool) -> 'a t -> 'a t
drop_while
.val filter_map : ('a -> 'b option) -> 'a t -> 'b t
val zip_index : 'a t -> (int * 'a) t
val unzip : ('a * 'b) t -> 'a t * 'b t
val partition : ('a -> bool) -> 'a t -> 'a t * 'a t
partition p l
returns the elements that satisfy p
,
and the elements that do not satisfy p
val for_all : ('a -> bool) -> 'a t -> bool
val exists : ('a -> bool) -> 'a t -> bool
val min : ?lt:('a -> 'a -> bool) -> 'a t -> 'a
Invalid_argument
if the generator is emptyval max : ?lt:('a -> 'a -> bool) -> 'a t -> 'a
val eq : ?eq:('a -> 'a -> bool) -> 'a t -> 'a t -> bool
val lexico : ?cmp:('a -> 'a -> int) -> 'a t -> 'a t -> int
val compare : ?cmp:('a -> 'a -> int) -> 'a t -> 'a t -> int
Gen_intf.S.lexico
val find : ('a -> bool) -> 'a t -> 'a option
find p e
returns the first element of e
to satisfy p
,
or None.val sum : int t -> int
val map2 : ('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t
val iter2 : ('a -> 'b -> unit) -> 'a t -> 'b t -> unit
val fold2 : ('acc -> 'a -> 'b -> 'acc) ->
'acc -> 'a t -> 'b t -> 'acc
val for_all2 : ('a -> 'b -> bool) -> 'a t -> 'b t -> bool
val exists2 : ('a -> 'b -> bool) -> 'a t -> 'b t -> bool
val zip_with : ('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t
val zip : 'a t -> 'b t -> ('a * 'b) t
val merge : 'a Gen_intf.gen t -> 'a t
e1, e2, ...
picks elements in e1
, e2
,
in e3
, e1
, e2
.... Once a generator is empty, it is skipped;
when they are all empty, and none remains in the input,
their merge is also empty.
For instance, merge [1;3;5] [2;4;6]
will be, in disorder, 1;2;3;4;5;6
.val intersection : ?cmp:('a -> 'a -> int) ->
'a t -> 'a t -> 'a t
val sorted_merge : ?cmp:('a -> 'a -> int) ->
'a t -> 'a t -> 'a t
val sorted_merge_n : ?cmp:('a -> 'a -> int) -> 'a t list -> 'a t
val tee : ?n:int -> 'a t -> 'a Gen_intf.gen list
n
generators (default 2). The generators
share the same underlying instance of the gen, so the optimal case is
when they are consumed evenlyval round_robin : ?n:int -> 'a t -> 'a Gen_intf.gen list
n
generators in a fair way. Elements with
index = k mod n
with go to the k-th gen. n
default value
is 2.val interleave : 'a t -> 'a t -> 'a t
interleave a b
yields an element of a
, then an element of b
,
and so on. When a generator is exhausted, this behaves like the
other generator.val intersperse : 'a -> 'a t -> 'a t
val product : 'a t -> 'b t -> ('a * 'b) t
val group : ?eq:('a -> 'a -> bool) -> 'a t -> 'a list t
val uniq : ?eq:('a -> 'a -> bool) -> 'a t -> 'a t
fun e -> map List.hd (group e)
.val sort : ?cmp:('a -> 'a -> int) -> 'a t -> 'a t
val sort_uniq : ?cmp:('a -> 'a -> int) -> 'a t -> 'a t
val chunks : int -> 'a t -> 'a array t
chunks n e
returns a generator of arrays of length n
, composed
of successive elements of e
. The last array may be smaller
than n
val permutations : 'a t -> 'a list t
val permutations_heap : 'a t -> 'a array t
val combinations : int -> 'a t -> 'a list t
combinations 2 (1--3) |> to_list = [[1;2]; [1;3]; [2;3]]
val power_set : 'a t -> 'a list t
val of_list : 'a list -> 'a t
val to_list : 'a t -> 'a list
val to_rev_list : 'a t -> 'a list
val to_array : 'a t -> 'a array
val of_array : ?start:int -> ?len:int -> 'a array -> 'a t
val of_string : ?start:int -> ?len:int -> string -> char t
val to_string : char t -> string
val to_buffer : Buffer.t -> char t -> unit
val rand_int : int -> int t
val int_range : ?step:int -> int -> int -> int t
int_range ~step a b
generates integers between a
and b
, included,
with steps of length step
(1 if omitted). a
is assumed to be smaller
than b
, otherwise the result will be empty.Invalid_argument
if step=0
step
: step between two numbers; must not be zero,
but it can be negative for decreasing ranges (val lines : char t -> string t
val unlines : string t -> char t
'\n'
after each onemodule Infix:sig
..end
val (--) : int -> int -> int t
int_range ~by:1
val (>>=) : 'a t -> ('a -> 'b Gen_intf.gen) -> 'b t
val (>>|) : 'a t -> ('a -> 'b) -> 'b t
val (>|=) : 'a t -> ('a -> 'b) -> 'b t
val pp : ?start:string ->
?stop:string ->
?sep:string ->
?horizontal:bool ->
(Format.formatter -> 'a -> unit) ->
Format.formatter -> 'a t -> unit