package containers

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
type 'a t

An IO stream of values of type 'a, consumable (iterable only once)

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

Map values with actions

val map_pure : ('a -> 'b) -> 'a t -> 'b t

Map values with a pure function

val filter_map : ('a -> 'b option) -> 'a t -> 'b t
val filter : ('a -> bool) -> 'a t -> 'a t
val flat_map : ('a -> 'b t io) -> 'a t -> 'b t

Map each value to a sub sequence of values

val take : int -> 'a t -> 'a t
val drop : int -> 'a t -> 'a t
val take_while : ('a -> bool io) -> 'a t -> 'a t
val drop_while : ('a -> bool io) -> 'a t -> 'a t
val general_iter : ('b -> 'a -> [ `Stop | `Continue of 'b * 'c option ] io) -> 'b -> 'a t -> 'c t

general_iter f acc seq performs a filter_map over seq, using f. f is given a state and the current value, and can either return `Stop to indicate it stops traversing, or `Continue (st, c) where st is the new state and c an optional output value. The result is the stream of values output by f

val tee : ('a -> unit io) list -> 'a t -> 'a t

tee funs seq behaves like seq, but each element is given to every function f in funs. This function f returns an action that is eagerly executed.

Consume
val iter : ('a -> _ io) -> 'a t -> unit io

Iterate on the stream, with an action for each element

val length : _ t -> int io

Length of the stream

val fold : ('b -> 'a -> 'b io) -> 'b -> 'a t -> 'b io

fold f acc seq folds over seq, consuming it. Every call to f has the right to return an IO value.

val fold_pure : ('b -> 'a -> 'b) -> 'b -> 'a t -> 'b io

fold f acc seq folds over seq, consuming it. f is pure.

Standard Wrappers
type 'a step_result =
  1. | Yield of 'a
  2. | Stop
type 'a gen = unit -> 'a step_result io
val of_fun : 'a gen -> 'a t

Create a stream from a function that yields an element or stops

val empty : 'a t
val singleton : 'a -> 'a t
val cons : 'a -> 'a t -> 'a t
val of_list : 'a list -> 'a t
val of_array : 'a array -> 'a t
val chunks : size:int -> Pervasives.in_channel -> string t

Read the channel's content into chunks of size size

val lines : Pervasives.in_channel -> string t

Lines of an input channel

val words : string t -> string t

Split strings into words at " " boundaries. NOT IMPLEMENTED

val output : ?sep:string -> Pervasives.out_channel -> string t -> unit io

output oc seq outputs every value of seq into oc, separated with the optional argument sep (default: None). It blocks until all values of seq are produced and written to oc.

OCaml

Innovation. Community. Security.