Purely functional streams
Contrarily to OCaml module Stream, these are meant to be used purely functionally. This implies in particular that accessing an element does not discard it.
type 'a node = | Nil |
| Cons of 'a * 'a t | View type to decompose and build streams. |
Constructors
val cons : 'a -> 'a t -> 'a tAppend an element in front of a stream.
val thunk : (unit -> 'a node) -> 'a tInternalize the laziness of a stream.
Destructors
val is_empty : 'a t -> boolWhethere a stream is empty.
val peek : 'a t -> 'a nodeReturn the head and the tail of a stream, if any.
Standard operations
All stream-returning functions are lazy. The other ones are eager.
val app : 'a t -> 'a t -> 'a tAppend two streams. Not tail-rec.
val map : ('a -> 'b) -> 'a t -> 'b tMapping of streams. Not tail-rec.
val iter : ('a -> unit) -> 'a t -> unitval fold : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'aval concat : 'a t t -> 'a tAppends recursively a stream of streams.
val map_filter : ('a -> 'b option) -> 'a t -> 'b tMixing map and filter. Not tail-rec.
val concat_map : ('a -> 'b t) -> 'a t -> 'b tconcat_map f l is the same as concat (map f l).
Conversions
val of_list : 'a list -> 'a tConvert a list into a stream.
val to_list : 'a t -> 'a listConvert a stream into a list.
Other