kristianmandrup / bs-mithril-stream Goto Github PK
View Code? Open in Web Editor NEWBucklescript bindings for mithril-stream stream library
Bucklescript bindings for mithril-stream stream library
After taking a look at the docs ( https://mithril.js.org/stream.html#stream ), I believe Mithril streams are implemented as essentially callbacks. E.g. in https://mithril.js.org/stream.html#combining-streams there's an example:
var a = stream(5)
var b = stream(7)
var added = stream.combine(function(a, b) {
return a() + b()
}, [a, b])
console.log(added()) // logs 12
According to the docs for combine
, the a
and b
that get passed into the combiner function are themselves stream values. Since they get called as functions, therefore they must be functions. So based on that, I came up with the following sample set of bindings to give you an idea of the approach I would take:
/* Mithril_Stream.re */
/** Need to uncurry to prevent generating JS like x(0)
See https://bucklescript.github.io/docs/en/function#curry-uncurry */
type t('a) = (. unit) => 'a;
/* See
https://bucklescript.github.io/docs/en/import-export#import-a-default-value
Test: let s = make(1); */
[@bs.module] external make: 'a => t('a) = "mithril/stream";
/* See https://bucklescript.github.io/docs/en/common-data-types#tuple
Test:
let s1 = make(1);
let s2 = make(2);
let s3 = combine2((. s1, s2) => s1(. ) + s2(. ), (s1, s2)); */
[@bs.module "mithril/stream"] external combine2: (
(. t('a1), t('a2)) => 'b,
(t('a1), t('a2)),
) => t('b) = "combine";
[@bs.module "mithril/stream"] external combine3: (
(. t('a1), t('a2), t('a3)) => 'b,
(t('a1), t('a2), t('a3)),
) => t('b) = "combine";
[@bs.module "mithril/stream"] external combine4: (
(. t('a1), t('a2), t('a3), t('a4)) => 'b,
(t('a1), t('a2), t('a3), t('a4)),
) => t('b) = "combine";
/* Test:
let s = make(1);
let t = map((. x) => x + 1, s); */
[@bs.send.pipe: t('a)] external map: ((. 'a) => 'b) => t('b) = "";
[@bs.send.pipe: t('a)]
tells BuckleScript to inject a final parameter of type t('a)
into the external, and generate a method call to that parameter. It's very useful but was somewhat prematurely removed from the BuckleScript doc site.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.