UNPKG

wonka

Version:

A fast push & pull stream library for Reason, loosely following the [callbag spec](https://github.com/callbag/callbag)

70 lines (64 loc) 2.65 kB
import * as Block from "bs-platform/lib/es6/block.js"; import * as Curry from "bs-platform/lib/es6/curry.js"; import * as Caml_option from "bs-platform/lib/es6/caml_option.js"; function sample(notifier) { return (function (source) { return (function (sink) { var state = /* record */[ /* ended */false, /* value */undefined, /* sourceTalkback */(function (param) { return /* () */0; }), /* notifierTalkback */(function (param) { return /* () */0; }) ]; Curry._1(source, (function (signal) { if (typeof signal === "number") { state[/* ended */0] = true; state[/* notifierTalkback */3](/* Close */1); return sink(/* End */0); } else if (signal.tag) { state[/* value */1] = Caml_option.some(signal[0]); return /* () */0; } else { state[/* sourceTalkback */2] = signal[0]; return /* () */0; } })); Curry._1(notifier, (function (signal) { var match = state[/* value */1]; if (typeof signal === "number") { state[/* ended */0] = true; state[/* sourceTalkback */2](/* Close */1); return sink(/* End */0); } else if (signal.tag) { if (match !== undefined && !state[/* ended */0]) { state[/* value */1] = undefined; return sink(/* Push */Block.__(1, [Caml_option.valFromOption(match)])); } else { return /* () */0; } } else { state[/* notifierTalkback */3] = signal[0]; return /* () */0; } })); return sink(/* Start */Block.__(0, [(function (signal) { if (signal) { state[/* ended */0] = true; state[/* sourceTalkback */2](/* Close */1); return state[/* notifierTalkback */3](/* Close */1); } else { state[/* sourceTalkback */2](/* Pull */0); return state[/* notifierTalkback */3](/* Pull */0); } })])); }); }); } export { sample , } /* No side effect */