Stdlib.Stream(3)
π Stdlib.Stream π
okay so you opened the Stdlib.Stream(3) page from the OCaml library manual, and we're about to make streams make sense, bestie β¨
πΈ NAME πΈ
Stdlib.Stream β no description. That's literally it, no cap π (the description is just "no description", iconic minimalism).
π¦ Module π¦
Module Stdlib.Stream.
π Documentation π
Module Stream : (module Stdlib__Stream).
type 'a tβ the type of streams holding values of type'a.exception Failureβ raised by parsers when none of the first components of the stream patterns is accepted.exception Error of stringβ raised by parsers when the first component of a stream pattern is accepted, but one of the following components is rejected.
β¨ Stream builders β¨
builders gonna build, and these ones are giving construction energy π§
val from : (int -> 'a option) -> 'a tβStream.from freturns a stream built from the functionf. To create a new stream element, the functionfis called with the current stream count. The user functionfmust return eitherSome <value>for a value orNoneto specify the end of the stream. Do note that the indices passed tofmay not start at0in the general case. For example,[< '0; '1; Stream.from f >]would callfthe first time with count2.val of_list : 'a list -> 'a tβ return the stream holding the elements of the list in the same order π«Άval of_string : string -> char tβ return the stream of the characters of the string parameter.val of_bytes : bytes -> char tβ return the stream of the characters of the bytes parameter. Since4.02.0βval of_channel : in_channel -> char tβ return the stream of the characters read from the input channel.
π Stream iterator π
val iter : ('a -> unit) -> 'a t -> unitβStream.iter f sscans the whole streams, applying functionfin turn to each stream element encountered. it's giving "touch every element, bestie" π
π₯ Predefined parsers π₯
val next : 'a t -> 'aβ return the first element of the stream and remove it from the stream. RaisesStream.Failureif the stream is empty πval empty : 'a t -> unitβ return()if the stream is empty, else raiseStream.Failure.
π Useful functions π
val peek : 'a t -> 'a optionβ returnSomeof "the first element" of the stream, orNoneif the stream is empty πval junk : 'a t -> unitβ remove the first element of the stream, possibly unfreezing it before.val count : 'a t -> intβ return the current count of the stream elements, i.e. the number of the stream elements discarded.val npeek : int -> 'a t -> 'a listβnpeek nreturns the list of thenfirst elements of the stream, or all its remaining elements if less thannelements are available.
okay that's the whole page bestie π«Ά this iconic manual moment was brought to you by OCamldoc, dated 2026-09-24, and it's Stdlib.Stream(3) forever πβ¨
π¦ where this page comes from
- alpine 3.24: ocaml-doc 4.14.4-r0 Β· LGPL-2.1-or-later WITH OCaml-LGPL-linking-exception
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms