made with esnextbin
Last active
December 11, 2016 13:18
-
-
Save davidchase/655223cdbbdf5124a6d78588340747dd to your computer and use it in GitHub Desktop.
esnextbin sketch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>ESNextbin Sketch</title> | |
</head> | |
<body> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "esnextbin-sketch", | |
"version": "0.0.0", | |
"dependencies": { | |
"data.task": "3.1.1", | |
"babel-runtime": "6.18.0" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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