Skip to content

Instantly share code, notes, and snippets.

@tusharmath
Last active April 11, 2017 09:33
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 tusharmath/ead4236e95b0e27b826d15a61990bd38 to your computer and use it in GitHub Desktop.
Save tusharmath/ead4236e95b0e27b826d15a61990bd38 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>
// write ES2015 code and import modules from npm
// and then press "Execute" to run your program
import * as O from 'observable-air'
import * as R from 'ramda'
console.clear()
const timeout = (t, v) => O.delay(t, O.of(v))
const prioritize = R.useWith(O.map, [
(p) => (v) => ({response: v, priority: p}),
R.identity
])
const A = prioritize(0, timeout(100, 'A'))
const B = prioritize(1, timeout(500, 'B'))
const C = prioritize(2, timeout(300, 'C'))
const DATA = O.merge(A, B, C)
const S = O.scan((m , v) => {
const {queue, current} = m
const nQueue = [...queue]
nQueue[v.priority] = v.response
return {queue: nQueue, current}
}, {queue: new Array(3), current: 0}, DATA)
const LOG = O.forEach(console.log)
LOG(S)
{
"name": "esnextbin-sketch",
"version": "0.0.0",
"dependencies": {
"observable-air": "3.0.5",
"ramda": "0.23.0",
"babel-runtime": "6.22.0"
}
}
'use strict';
var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray');
var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2);
var _observableAir = require('observable-air');
var O = _interopRequireWildcard(_observableAir);
var _ramda = require('ramda');
var R = _interopRequireWildcard(_ramda);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// write ES2015 code and import modules from npm
// and then press "Execute" to run your program
console.clear();
var timeout = function timeout(t, v) {
return O.delay(t, O.of(v));
};
var prioritize = R.useWith(O.map, [function (p) {
return function (v) {
return { response: v, priority: p };
};
}, R.identity]);
var A = prioritize(0, timeout(100, 'A'));
var B = prioritize(1, timeout(500, 'B'));
var C = prioritize(2, timeout(300, 'C'));
var DATA = O.merge(A, B, C);
var S = O.scan(function (m, v) {
var queue = m.queue;
var current = m.current;
var nQueue = [].concat((0, _toConsumableArray3.default)(queue));
nQueue[v.priority] = v.response;
return { queue: nQueue, current: current };
}, { queue: new Array(3), current: 0 }, DATA);
var LOG = O.forEach(console.log);
LOG(S);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment