Module Async_extended.Generator

A generator is a consumer-driven source of data. Unlike Async streams, these * objects are stateful. For example, if one generator is shared between two clients * that both invoke next, then they will see different sequences of items

type 'a t
val empty : 'a t
val create : (unit ‑> [ `Done | `Ok of 'a ] Async.Deferred.t) ‑> 'a t
val unfold : 'state ‑> ('state ‑> [ `Done | `Ok of 'a * 'state ] Async.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.Deferred.t

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

val fold' : 'a t ‑> init:'b ‑> f:('b ‑> 'a ‑> 'b Async.Deferred.t) ‑> 'b Async.Deferred.t
val fold : 'a t ‑> init:'b ‑> f:('b ‑> 'a ‑> 'b) ‑> 'b Async.Deferred.t
val iter' : 'a t ‑> f:('a ‑> unit Async.Deferred.t) ‑> unit Async.Deferred.t
val iter : 'a t ‑> f:('a ‑> unit) ‑> unit Async.Deferred.t
val to_list : 'a t ‑> 'a list Async.Deferred.t

Generates all elements from generator and returns the resulting list.

val map' : 'a t ‑> f:('a ‑> 'b Async.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.Deferred.t
val to_stream : 'a t ‑> 'a Async.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