Up

Module Generator = Generator

Signature

type 'a t
val empty : 'a t
val create : (unit -> [
| `Done
| `Ok of 'a
] Async.Std.Deferred.t) -> 'a t
val unfold : 'state -> ('state -> [
| `Done
| `Ok of 'a * 'state
] Async.Std.Deferred.t) -> 'a t
val singleton : 'a -> 'a t

singleton x creates a generator containing only x.

val of_list : 'a list -> 'a t
val find : 'a t -> f:('a -> bool) -> 'a option Async.Std.Deferred.t

find gen ~f finds the first item for which f item is true.

Returns first item in generator for which f item is true, or None if no such element is found.
val fold' : 'a t -> init:'b -> f:('b -> 'a -> 'b Async.Std.Deferred.t) -> 'b Async.Std.Deferred.t
val fold : 'a t -> init:'b -> f:('b -> 'a -> 'b) -> 'b Async.Std.Deferred.t
val iter' : 'a t -> f:('a -> unit Async.Std.Deferred.t) -> unit Async.Std.Deferred.t
val iter : 'a t -> f:('a -> unit) -> unit Async.Std.Deferred.t
val to_list : 'a t -> 'a list Async.Std.Deferred.t

Generates all elements from generator and returns the resulting list.

Returns list of elements generated in the order in which they were generated.
val map' : 'a t -> f:('a -> 'b Async.Std.Deferred.t) -> 'b t

map' t f creates a new generator that with the result of the deferred (f v), for each element v of t.

val map : 'a t -> f:('a -> 'b) -> 'b t

map t f creates a new generator that with one element, (f v), for each element v of t.

val filter_map : 'a t -> f:('a -> 'b option) -> 'b t
val filter_opt : 'a option t -> 'a t
val next : 'a t -> [
| `Done
| `Ok of 'a
] Async.Std.Deferred.t
val to_stream : 'a t -> 'a Async.Std.Stream.t
val append : 'a t -> 'a t -> 'a t

append t1 t2 creates a new generator that first echos t1 until it is done, then echos t2

val concat : 'a t t -> 'a t

concat t creates a new generator echos in sequence each generator generated by t