.TH "Stream" 3o source: 2019-01-25 OCamldoc "OCaml library" .SH NAME Stream \- Streams and parsers. .SH Module Module Stream .SH Documentation .sp Module .BI "Stream" : .B sig end .sp Streams and parsers\&. .sp .sp .sp .I type .B 'a .I t .sp The type of streams holding values of type .B \&'a \&. .sp .I exception Failure .sp Raised by parsers when none of the first components of the stream patterns is accepted\&. .sp .I exception Error .B of .B string .sp Raised by parsers when the first component of a stream pattern is accepted, but one of the following components is rejected\&. .sp .PP .B === .B Stream builders .B === .PP .I val from : .B (int -> 'a option) -> 'a t .sp .B Stream\&.from f returns a stream built from the function .B f \&. To create a new stream element, the function .B f is called with the current stream count\&. The user function .B f must return either .B Some for a value or .B None to specify the end of the stream\&. .sp Do note that the indices passed to .B f may not start at .B 0 in the general case\&. For example, .B [< \&'0; \&'1; Stream\&.from f >] would call .B f the first time with count .B 2 \&. .sp .I val of_list : .B 'a list -> 'a t .sp Return the stream holding the elements of the list in the same order\&. .sp .I val of_string : .B string -> char t .sp Return the stream of the characters of the string parameter\&. .sp .I val of_bytes : .B bytes -> char t .sp Return the stream of the characters of the bytes parameter\&. .sp .B "Since" 4.02.0 .sp .I val of_channel : .B Pervasives.in_channel -> char t .sp Return the stream of the characters read from the input channel\&. .sp .PP .B === .B Stream iterator .B === .PP .I val iter : .B ('a -> unit) -> 'a t -> unit .sp .B Stream\&.iter f s scans the whole stream s, applying function .B f in turn to each stream element encountered\&. .sp .PP .B === .B Predefined parsers .B === .PP .I val next : .B 'a t -> 'a .sp Return the first element of the stream and remove it from the stream\&. Raise .B Stream\&.Failure if the stream is empty\&. .sp .I val empty : .B 'a t -> unit .sp Return .B () if the stream is empty, else raise .B Stream\&.Failure \&. .sp .PP .B === .B Useful functions .B === .PP .I val peek : .B 'a t -> 'a option .sp Return .B Some of "the first element" of the stream, or .B None if the stream is empty\&. .sp .I val junk : .B 'a t -> unit .sp Remove the first element of the stream, possibly unfreezing it before\&. .sp .I val count : .B 'a t -> int .sp Return the current count of the stream elements, i\&.e\&. the number of the stream elements discarded\&. .sp .I val npeek : .B int -> 'a t -> 'a list .sp .B npeek n returns the list of the .B n first elements of the stream, or all its remaining elements if less than .B n elements are available\&. .sp