Mirror: 🎩 A tiny but capable push & pull stream library for TypeScript and Flow

Add initial comments as documentation to the signature files

Changed files
+76 -5
src
+65 -5
src/callbag.rei
···
open Callbag_types;
+
/* -- source factories */
+
+
/* Accepts a list and creates a pullable source for that list.
+
The source will emit events when being pulled until the list
+
is exhausted and it completes */
let fromList: (list('a), signalT('a) => unit) => unit;
+
+
/* Accepts an array and creates a pullable source for that array.
+
The source will emit events when being pulled until the array
+
is exhausted and it completes */
let fromArray: (array('a), signalT('a) => unit) => unit;
-
let map: ('a => 'b, (signalT('a) => unit) => unit, signalT('b) => unit) => unit;
-
let filter: ('a => bool, (signalT('a) => unit) => unit, signalT('a) => unit) => unit;
-
let scan: (('b, 'a) => 'b, 'b, (signalT('a) => unit) => unit, signalT('b) => unit) => unit;
+
/* -- operators */
+
+
/* Takes a mapping function from one type to another, and a source,
+
and creates a sink & source.
+
All values that it receives will be transformed using the mapping
+
function and emitted on the new source */
+
let map:
+
('a => 'b, (signalT('a) => unit) => unit, signalT('b) => unit) => unit;
+
+
/* Takes a predicate function returning a boolean, and a source,
+
and creates a sink & source.
+
All values that it receives will be filtered using the predicate,
+
and only truthy values will be passed on to the new source.
+
The sink will attempt to pull a new value when one was filtered. */
+
let filter:
+
('a => bool, (signalT('a) => unit) => unit, signalT('a) => unit) => unit;
+
+
/* Takes a reducer function, a seed value, and a source, and creates
+
a sink & source.
+
The last returned value from the reducer function (or the seed value
+
initially) will be passed to the reducer together with the value
+
that the sink receives. All return values of the reducer function
+
are emitted on the new source. */
+
let scan:
+
(('b, 'a) => 'b, 'b, (signalT('a) => unit) => unit, signalT('b) => unit) =>
+
unit;
+
+
/* Takes an array of sources and creates a sink & source.
+
All values that the sink receives from all sources will be passed through
+
to the new source */
let merge: (array((signalT('a) => unit) => unit), signalT('a) => unit) => unit;
+
+
/* Takes a listenable or a pullable source and creates a new source that
+
will ensure that the source is shared between all sinks that follow.
+
Essentially the original source will only be created once. */
let share: ((signalT('a) => unit) => unit, signalT('a) => unit) => unit;
-
let combine: ((signalT('a) => unit) => unit, (signalT('b) => unit) => unit, signalT(('a, 'b)) => unit) => unit;
+
+
/* Takes two sources and creates a new source & sink.
+
All latest values from both sources will be passed through as a
+
tuple of the last values that have been observed */
+
let combine:
+
(
+
(signalT('a) => unit) => unit,
+
(signalT('b) => unit) => unit,
+
signalT(('a, 'b)) => unit
+
) =>
+
unit;
+
+
/* -- sink factories */
+
/* Takes a function and a source, and creates a sink.
+
The function will be called for each value that the sink receives.
+
The sink will attempt to pull new values as values come in, until
+
the source ends. */
let forEach: ('a => unit, (signalT('a) => unit) => unit) => unit;
-
let subscribe: ('a => unit, (signalT('a) => unit) => unit) => (unit => unit);
+
+
/* Similar to the `forEach` sink factory, but returns an anonymous function
+
that when called will end the stream immediately.
+
Ending the stream will propagate an End signal upwards to the root source. */
+
let subscribe: ('a => unit, (signalT('a) => unit) => unit, unit) => unit;
+11
src/callbagJs.rei
···
open Callbag_types;
+
/* -- source factories */
+
+
/* Accepts a period in milliseconds and creates a listenable source
+
that emits ascending numbers for each time the interval fires.
+
This stream will emit values indefinitely until it receives an
+
End signal from a talkback passed downwards to its sink. */
let interval: (int, signalT(int) => unit) => unit;
+
+
/* Accepts a JS promise and creates a listenable source that emits
+
the promise's value once it resolves.
+
This stream will wait for the promise's completion, unless it
+
receives an End signal first. */
let fromPromise: (Js.Promise.t('a), signalT('a) => unit) => unit;