Hcs.Stream.Sync

hcs · API reference

Synchronous Stream

A simple pull-based stream using OCaml's Seq.

type 'a t = 'a Seq.t

A synchronous stream of values

Producers

val empty : 'a t
val singleton : 'a -> 'a t
val of_list : 'a list -> 'a t
val of_array : 'a array -> 'a t
val unfold : ('s -> ('a * 's) option) -> 's -> 'a t

Create a stream from an unfolding function

val repeat : int -> 'a -> 'a t

Create a stream that repeats a value n times

val generate : (unit -> 'a option) -> 'a t

Create a stream from a generator function

Transformers

val map : ('b -> 'a) -> 'b Seq.t -> 'a t
val filter : ('a -> bool) -> 'a Seq.t -> 'a t
val filter_map : ('b -> 'a option) -> 'b Seq.t -> 'a t
val take : int -> 'a Seq.t -> 'a t

Take the first n elements

val drop : int -> 'a Seq.t -> 'a t

Drop the first n elements

val chunks : int -> 'a Seq.t -> 'a list t

Split stream into chunks of size n

val flatten : 'a Seq.t Seq.t -> 'a t

Flatten a stream of streams

val append : 'a Seq.t -> 'a Seq.t -> 'a t

Append two streams

Consumers

val fold : ('a -> 'b -> 'a) -> 'a -> 'b Seq.t -> 'a

Fold over the stream

val iter : ('a -> unit) -> 'a Seq.t -> unit

Iterate over the stream for side effects

val drain : 'a Seq.t -> unit

Drain the stream, discarding all values

val to_list : 'a Seq.t -> 'a list

Collect stream into a list

val to_array : 'a Seq.t -> 'a array

Collect stream into an array

Cstruct-specific operations

val cstructs_to_string : Cstruct.t t -> string

Concatenate a stream of Cstructs into a single string

val string_to_cstructs : ?chunk_size:int -> string -> Cstruct.t t

Split a string into chunks of Cstructs