Library
Module
Module type
Parameter
Class
Class type
Module with definitions for flows.
Flows define streaming transformation, filtering or groupping operations that are fully disconnected from input and output. Their implementation intercepts an internal folding function and modifies the input one value at a time.
Flows are a great way to define decoupled transformations that can be used with Stream.via
.
A flow can be applied to a stream with Stream.via
:
# Stream.range 10 100
|> Stream.via (Flow.map (fun x -> x + 1))
|> Stream.into Sink.sum
- : int = 4995
Flows can also be composed to form a pipeline:
# let flow = Flow.(map (fun x -> x + 1) >> filter (fun x -> x mod 2 = 0)) in
Stream.range 10 100
|> Stream.via flow
|> Stream.into Sink.sum
- : int = 2475
type ('a, 'b) t = ('a, 'b) flow
val filter : ('a -> bool) -> ('a, 'a) t
A flow that includes only the elements that satisfy a predicate.
val map : ('a -> 'b) -> ('a, 'b) t
A flow with all elements transformed with a mapping function.
val take : int -> ('a, 'a) t
Take first n
elements from the source and discard the rest.
val buffer : int -> ('a, 'a array) t
Collects n
elements into an array buffer. Once the buffer is full it is emmited as a stream item.
through sink
repeatedly processes incoming elements with sink
producing computed results.
Note: The provided sink might consume the whole input if it is infinite, or if the input terminates before filling the sink.
val identity : ('a, 'a) t
A neutral flow that does not change the elements.
Composes two flows from right to left.
More precisely f1 << f2
is compose f1 f2
.