Module Lambda_streams.Sync
type 'a connection= ('a input, unit output) Connection.tRepresents a connection-based input stream with an output stream to close it.
val make_input : (unit -> 'a) -> 'a inputval make_output : ('a -> unit) -> 'a outputval make_mutator : initial:'a -> 'a input * 'a outputCreates a mutator: a pair of input and output streams that together behave like a mutable variable. Mutating the value is accomplished by sending data to the output stream. Fetching the current value is done by reading the input stream.
val pure : 'a -> 'a inputval enumerate : unit -> int inputCreates an input stream that enumerates the natural numbers.
val next : 'a input -> 'aGets the next value (or current value if it's a behavior) from the input stream.
val send : 'a -> 'a output -> unitSends a single value to the output stream. Semantically equivalent to:
Finite.Sync.pure value |> Finite.Sync.pipe output_streamBut it's more efficient because it doesn't involve instatiating an input stream.
val accumulate : int -> ('b -> 'a -> 'b) -> 'b -> 'a input -> 'bLike fold_left but for infinite streams, ending at signal n.
val map : ('a -> 'b) -> 'a input -> 'b inputval filter : ('a -> bool) -> 'a input -> 'a inputFilters the input stream based on a predicate. This function returns a stream that, when invoked, will continue to invoke the original input stream until a value that satisfies the predicate is given, which is then returned. This means that an invocation of the returned stream may possibly never terminate.
For example:
enumerate () |> filter ((>=) 10)Will block and never terminate after
10invocations, because after those invocations any future values ofenumerate ()will never be less than10.On the other hand,
let is_even x = x mod 2 = 0 in enumerate () |> filter is_evenWill always return a value, because there will always be a successor to a natural number that is even (every other number).