Skip to content

Instantly share code, notes, and snippets.

@davidchase
Last active December 11, 2016 13:18
Show Gist options
  • Save davidchase/655223cdbbdf5124a6d78588340747dd to your computer and use it in GitHub Desktop.
Save davidchase/655223cdbbdf5124a6d78588340747dd to your computer and use it in GitHub Desktop.
esnextbin sketch
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>ESNextbin Sketch</title>
</head>
<body>
</body>
</html>
console.clear()
import Task from 'data.task'
const to = promise =>
new Task((rej, resolve) => promise.then(resolve).catch(rej))
const from = task =>
new Promise((resolve, rej) => task.fork(rej, resolve))
const ISO = (to, from) => ({
to,
from
})
const futures = ISO(to, from)
//futures.to(futures.from(Task.of('world'))).fork(console.warn, console.log)
//futures.from(futures.to(Promise.resolve('hey!'))).then(console.log)
futures.from(futures.to(Promise.resolve('hello')).map(x => x + "!"))
.then(console.log)
{
"name": "esnextbin-sketch",
"version": "0.0.0",
"dependencies": {
"data.task": "3.1.1",
"babel-runtime": "6.18.0"
}
}
'use strict';
var _promise = require('babel-runtime/core-js/promise');
var _promise2 = _interopRequireDefault(_promise);
var _data = require('data.task');
var _data2 = _interopRequireDefault(_data);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
console.clear();
var to = function to(promise) {
return new _data2.default(function (rej, resolve) {
return promise.then(resolve).catch(rej);
});
};
var from = function from(task) {
return new _promise2.default(function (resolve, rej) {
return task.fork(rej, resolve);
});
};
var ISO = function ISO(to, from) {
return {
to: to,
from: from
};
};
var futures = ISO(to, from);
//futures.to(futures.from(Task.of('world'))).fork(console.warn, console.log)
//futures.from(futures.to(Promise.resolve('hey!'))).then(console.log)
futures.from(futures.to(_promise2.default.resolve('hello')).map(function (x) {
return x + "!";
})).then(console.log);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment