Skip to content

Instantly share code, notes, and snippets.

@TylorS
Last active April 28, 2017 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TylorS/5fdc3a823cfa07855944cba9ef2df3cd to your computer and use it in GitHub Desktop.
Save TylorS/5fdc3a823cfa07855944cba9ef2df3cd to your computer and use it in GitHub Desktop.
esnextbin sketch
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>ESNextbin Sketch</title>
<!-- put additional styles and scripts here -->
</head>
<body>
<!-- put markup and other contents here -->
</body>
</html>
import {
fromArray,
just,
merge,
map,
empty,
concat,
zip,
startWith,
runEffects,
tap
} from '@most/core'
import { hold } from '@most/hold'
import { newDefaultScheduler } from '@most/scheduler'
console.clear()
const scheduler = newDefaultScheduler()
const observe = (f, stream) => runEffects(tap(f, stream), scheduler)
const a = [1, 2, 3, 4].map(just).reduce(concat, empty())
const b = [5, 6, 7, 8].map(just).reduce(concat, empty())
const c = zip((a, b) => ({ a$: a, b$: b }), a, b)
const { a$, b$ } = partition({ a$: 0, b$: 4 }, c)
observe(x => console.log('a', x), a$)
observe(x => console.log('b', x), b$)
function partition (initial, streamOfObject) {
const obj = Object.create(null)
const obj$ = hold(streamOfObject)
const keys = Object.keys(initial)
for (let i = 0; i < keys.length; ++i) {
const key = keys[i]
obj[key] = hold(startWith(initial[key], map(o => o[key], obj$)))
}
return obj
}
{
"name": "esnextbin-sketch",
"version": "0.0.0",
"dependencies": {
"@most/core": "0.3.1",
"@most/hold": "2.0.0",
"@most/scheduler": "0.4.0",
"babel-runtime": "6.23.0"
}
}
'use strict';
var _keys = require('babel-runtime/core-js/object/keys');
var _keys2 = _interopRequireDefault(_keys);
var _create = require('babel-runtime/core-js/object/create');
var _create2 = _interopRequireDefault(_create);
var _core = require('@most/core');
var _hold = require('@most/hold');
var _scheduler = require('@most/scheduler');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
console.clear();
var scheduler = (0, _scheduler.newDefaultScheduler)();
var observe = function observe(f, stream) {
return (0, _core.runEffects)((0, _core.tap)(f, stream), scheduler);
};
var a = [1, 2, 3, 4].map(_core.just).reduce(_core.concat, (0, _core.empty)());
var b = [5, 6, 7, 8].map(_core.just).reduce(_core.concat, (0, _core.empty)());
var c = (0, _core.zip)(function (a, b) {
return { a$: a, b$: b };
}, a, b);
var _partition = partition({ a$: 0, b$: 4 }, c);
var a$ = _partition.a$;
var b$ = _partition.b$;
observe(function (x) {
return console.log('a', x);
}, a$);
observe(function (x) {
return console.log('b', x);
}, b$);
function partition(initial, streamOfObject) {
var obj = (0, _create2.default)(null);
var obj$ = (0, _hold.hold)(streamOfObject);
var keys = (0, _keys2.default)(initial);
var _loop = function _loop(i) {
var key = keys[i];
obj[key] = (0, _hold.hold)((0, _core.startWith)(initial[key], (0, _core.map)(function (o) {
return o[key];
}, obj$)));
};
for (var i = 0; i < keys.length; ++i) {
_loop(i);
}
return obj;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment