package lambda_streams

  1. Overview
  2. Docs
Lambda-based streaming library

Install

Dune Dependency

Authors

Maintainers

Sources

0.1.2.tar.gz
md5=8c1ce04ee769b56434696bd57aee1a5b
sha512=9bb794f3852da60e536277f41ca5c6db678e5f0f5100ca13bf4c054a8d5c17834891c9ba2d73ddd35dc4f52f4b8be6076611b8f8c413eb6e93d61c161c67f9aa

doc/src/lambda_streams/Sync.ml.html

Source file Sync.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
type 'a input = unit -> 'a

and 'a output = 'a -> unit

type 'a connection = ('a input, unit output) Connection.t

let make_input f = f

let make_output f = f

let make_mutator ~initial =
  let value = ref initial in
  let input () = !value and output v = value := v in
  input, output

let pure value () = value

let enumerate () =
  let index = ref 0 in
  fun () ->
    index := !index + 1;
    !index

let next stream = stream ()

let send value output_stream = output_stream value

let pipe output_stream input_stream =
  while true do
    input_stream () |> output_stream
  done

let accumulate n f init stream =
  let index = ref 0 and acc = ref init in
  while !index < n do
    index := !index + 1;
    acc := f !acc (stream ())
  done;
  !acc

let map f stream () = stream () |> f

let filter f stream () =
  let value = ref @@ stream () in
  while not @@ f !value do
    value := stream ()
  done;
  !value

let scan f init stream =
  let acc = ref init in
  fun () ->
    acc := f !acc (stream ());
    !acc
OCaml

Innovation. Community. Security.