1/* A sink has the signature: `signalT('a) => unit`
2 * A source thus has the signature: `sink => unit`, or `(signalT('a) => unit) => unit`
3 *
4 * Effectively a sink is a callback receiving signals as its first argument.
5 * - Start(talkback) will be carrying a talkback using which the sink can attempt
6 * to pull values (Pull) or request the source to end its stream (End)
7 * - Push(payload) carries a value that the source sends to the sink.
8 * This can happen at any time, since a source can be both pullable or
9 * merely listenable.
10 * - End signifies the end of the source stream, be it because of a talkback (End)
11 * or because the source is exhausted.
12 *
13 * In detail, a talkback is simply a callback that receives a talkback signal as
14 * its first argument. It's thus typically anonymously created by the source.
15 *
16 * A source is a factory that accepts a sink. Calling a source with a sink will
17 * instantiate and initiate the source's stream, after which the source sends the sink
18 * a talkback (Start(talkback)). This is called the "handshake".
19 *
20 * Typically an operator factory won't call the source with a sink it receives
21 * immediately鈥攂ecause this would cause the operator to simply be a noop鈥攂ut instead
22 * it will create an intermediate sink with the same signature to perform its own
23 * logic.
24 *
25 * At that point the operator can for instance intercept the talkback for its own
26 * purposes, or call the actual sink as it sees fit.
27 */
28
29[@genType.import "./shims/Js.shim"]
30type talkbackT =
31 | Pull
32 | Close;
33
34[@genType.import "./shims/Js.shim"]
35type signalT('a) =
36 | Start((. talkbackT) => unit)
37 | Push('a)
38 | End;
39
40[@genType]
41type sinkT('a) = (. signalT('a)) => unit;
42
43[@genType]
44type sourceT('a) = sinkT('a) => unit;
45
46[@genType]
47type operatorT('a, 'b) = sourceT('a) => sourceT('b);
48
49[@genType]
50type teardownT = (. unit) => unit;
51
52[@genType]
53type subscriptionT = {unsubscribe: unit => unit};
54
55[@genType]
56type observerT('a) = {
57 next: 'a => unit,
58 complete: unit => unit,
59};
60
61[@genType]
62type subjectT('a) = {
63 source: sourceT('a),
64 next: 'a => unit,
65 complete: unit => unit,
66};
67
68/* Sinks and sources need to explicitly be their own callbacks;
69 * This means that currying needs to be forced for Bucklescript
70 * not to optimise them away
71 */
72external curry: 'a => 'a = "%identity";