package flux

  1. Overview
  2. Docs
Composable streaming abstractions with Miou

Install

dune-project
 Dependency

Authors

Maintainers

Sources

flux-0.0.1.beta7.tbz
sha256=4fe47605e171bdc7734d0cd4f3fa8ad5d7e4aa9b7cde8cd46e517dadf0f5dda9
sha512=a198e60da2575a27d6976bac2839e544312e4f5d895bc18bf3d9554396896a406a1143bcc0a28c75b992a060e0a5174a23a6688aaefaa8dd8c37f09b59364ad1

doc/flux/Flux/Stream/index.html

Module Flux.StreamSource

Creating streams.

Sourceval empty : 'a stream

Empty stream with no elements.

Sourceval range : ?by:int -> int -> int -> int stream

range ~by:step n m is a sequence of integers starting from n to m (excluding m) incremented by step. The range is pen on the right side.

Sourceval repeat : ?times:int -> 'a -> 'a stream

repeat ~times:n x produces a stream by repeating x n times. If n is omitted, x is repeated ad infinitum.

Sourceval unfold : 's -> ('s -> ('a * 's) option) -> 'a stream

unfold seed next is a stream created from a seed state and a function that produces elements and an updated state. The stream will terminate when next produces None.

Sourceval concat : 'a stream -> 'a stream -> 'a stream

concat s0 s1 is a stream that exhausts all elements from s0 and then all elements from s1.

Transforming a stream.

Sourceval map : ('a -> 'b) -> 'a stream -> 'b stream

A stream with all elements transformed with a mapping function.

Sourceval tap : ('a -> unit) -> 'a stream -> 'a stream

Pass each element through an effectful function.

Sourceval take : int -> 'a stream -> 'a stream

Take first n elements from the stream and discard the rest.

Sourceval filter : ('a -> bool) -> 'a stream -> 'a stream

A stream that includes only the elements that satisfy a predicate.

Sourceval filter_map : ('a -> 'b option) -> 'a stream -> 'b stream

filter_map fn src applies fn to every element x of source, discarding it if fn x produces None, and keeping the transformed value otherwise.

Combining streams.

Sourceval interpose : 'a -> 'a stream -> 'a stream

Inserts a separator element between each stream element.

Sourceval flat_map : ('a -> 'b stream) -> 'a stream -> 'b stream

flat_map fn stream is a stream concatenated from sub-streams produced by applying fn to all elements of stream.

Consumers.

Sourceval drain : 'a stream -> unit

Consume and discard all elements from the given stream.

Sourceval each : ?parallel:bool -> ('a -> unit) -> 'a stream -> unit

each fn stream applies an function fn to all elements of stream. Each function is performed cooperatively via the Miou scheduler.

Adaptors.

Sourceval into : ('a, 'b) sink -> 'a stream -> 'b

into sink stream is the result value produced by streaming all elements of stream into sink.

Sourceval via : ('a, 'b) flow -> 'a stream -> 'b stream

via flow stream is stream produced by transforming all elements of stream via flow.

Sourceval from : ?dispose_if_full:bool -> 'a source -> 'a stream

from source is a stream created from a source. To retain control over the given src resource, by default, if the stream has fully filled the result, the source is properly disposed of (i.e. its stop function is called correctly).

Sourceval run : from:'a source -> via:('a, 'b) flow -> into:('b, 'c) sink -> 'c * 'a source option

Fuses sources, sinks and flows and produces a result and a leftover.

let r, leftover = Stream.run ~from:source ~via:flow ~into:sink

Streams elements from source into sink via a stream transformer flow. In addition to the result value r produced by sink, a leftover source is returned, if source was not exhausted.

NOTE: If a leftover source is produced, it is required to either consume it or manually dispose its resources. Not doing so might lead to resource leaks.

I/O Streams.

Sourceval file : filename:string -> string stream -> unit

file filename stream writes bytes from stream into the file located at filename.