package flux
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=dbfb198a16aab3f8987cc2ba31bc8da3720b9031d2b6b1a3313e6c1342cbf4b3
sha512=ec0ab77c2b1db2fd730581cefbb92f8391c3f8801cd02bb558609f46daff493e8c513e1d0978d1cdc613ce7ef1799e144d1f9740e0863169e45992df4c117ba4
doc/flux/Flux/Source/index.html
Module Flux.SourceSource
unfold seed next is a finite source created from a seed state and a function that produces elements and an updated state.
seq items is a source with all elements from the items sequence.
array items is a source with all elements from the items array.
string str is a source with all characters from the str string.
bqueue ?stop q is a source with all iterms from the q bounded-queue.
The user can choose how to dispose the given bounded-queue q:
`Ignoredoes nothing`HaltBqueue.haltthe given bounded-queueq`CloseBqueue.closethe given bounded-queueq
NOTE: `Halt a bounded-queue created with Bqueue.with_close also closes the given bounded-queue.
file ~filename len reads at most len bytes of the file filename until the end.
in_channel ic reads strings from the given in_channel ic. If the given ic is not stdin and ?close is true (by default), dispose closes it properly.
Transforming a source.
NOTE: Instead ofapplying the transformation functions at the source, consider using Stream.from or defining your computation as a flow to make it reusable.
A source with all elements transformed with a mapping function.
Consuming a source.
each fn src applies an effectful function fn to all elements in src.
next src is Some (x, rest) where x is the first element of src and rest is src without x; or None, if src is empty.
NOTE: If rest is produced, it is required to either consume it or manually dispose its resources. Not doing so might lead to resource leaks.
Resource handling.
dispose src forces the termination of the source data. This function is useful in situations when a leftover source is produced in Stream.run.
NOTE: If the source is not already initialized, calling this function will first initialize its state before it is terminated.
Miou related functions.
resource ~finally pull value creates a new resource from a pull function and an initial value. resource uses Miou's ownership mechanism so that if the task consuming the resource is cancelled, the resource is properly released (and finally is executed).
This also requires the user to dispose the source at the end of the task, otherwise Miou's rules will be violated.
NOTE: The resource passed to the pull function is physically the same as init.
Type of tasks which should fill a given bounded-queue.
with_task ?halt ~size producer returns a source that is linked to a task producer producing elements of type 'a. The transfer of elements between the task and the source consumer is limited in memory by size elements at a time.
The source is not effective and may potentially block if the shared queue is empty and an attempt is made to consume it (via next, for example). The shared queue is closed/halted (depending on ?halt, defaults to false) only on abnormal situation (and the task is cancelled by the scheduler or if an exception was raised by producer). The user must close the given queue to emit the signal to other tasks that the queue has been closed.
For more details on the difference between halt and close, please refer to the Bqueue module.
with_formatter ?halt ~size producer is a specialisation of with_task with a Format.formatter. Everything written in the formatter is transmitted to the consumer.