Hcs.Stream.Sync
hcs · API reference
Synchronous Stream
A simple pull-based stream using OCaml's Seq.
type 'a t = 'a Seq.tA synchronous stream of values
Producers
val empty : 'a tval singleton : 'a -> 'a tval of_list : 'a list -> 'a tval of_array : 'a array -> 'a tval unfold : ('s -> ('a * 's) option) -> 's -> 'a tCreate a stream from an unfolding function
val repeat : int -> 'a -> 'a tCreate a stream that repeats a value n times
val generate : (unit -> 'a option) -> 'a tCreate a stream from a generator function
Transformers
val map : ('b -> 'a) -> 'b Seq.t -> 'a tval filter : ('a -> bool) -> 'a Seq.t -> 'a tval filter_map : ('b -> 'a option) -> 'b Seq.t -> 'a tval take : int -> 'a Seq.t -> 'a tTake the first n elements
val drop : int -> 'a Seq.t -> 'a tDrop the first n elements
val chunks : int -> 'a Seq.t -> 'a list tSplit stream into chunks of size n
val flatten : 'a Seq.t Seq.t -> 'a tFlatten a stream of streams
val append : 'a Seq.t -> 'a Seq.t -> 'a tAppend two streams
Consumers
val fold : ('a -> 'b -> 'a) -> 'a -> 'b Seq.t -> 'aFold over the stream
val iter : ('a -> unit) -> 'a Seq.t -> unitIterate over the stream for side effects
val drain : 'a Seq.t -> unitDrain the stream, discarding all values
val to_list : 'a Seq.t -> 'a listCollect stream into a list
val to_array : 'a Seq.t -> 'a arrayCollect stream into an array
Cstruct-specific operations
val cstructs_to_string : Cstruct.t t -> stringConcatenate a stream of Cstructs into a single string
val string_to_cstructs : ?chunk_size:int -> string -> Cstruct.t tSplit a string into chunks of Cstructs