Skip to content

Instantly share code, notes, and snippets.

View mishelashala's full-sized avatar

Michell Ayala mishelashala

  • Mérida, Yucatan
View GitHub Profile
// then :: ((a -> b), (c -> d)) -> Promise<b | d>
// then :: ((a -> Promise b), (c -> Promise d)) -> Promise<b | d>
// Now this a thunk.
// Yeah, computer science b*tch!
// PromisedNumber :: () -> Promise<number>
const PromisedNumber = () => new Promise(function (fulfill, reject) {
setTimeout(() => { fulfill(10) }, 500)
})
// PromisedString :: () -> Promise<string>
const PromisedString = () => new Promise(function (fulfill, reject) {
setTimeout(() => { fulfill(10) }, 1000)
})
// Promise<number>
var promisedNumber = new Promise(function (fulfill, reject) {
setTimeout(() => { fulfill(10) }, 500)
})
// Promise<string>
var promisedString = new Promise(function (fulfill, reject) {
setTimeout(() => { fulfill(10) }, 1000)
})
console.log('start')
// Promise<number>
var promisedNumber = new Promise(function (fulfill, reject) {
setTimeout(() => { fulfill(10) }, 1000)
});
// Promise<string>
var promisedString = new Promise(function (fulfill, reject) {
setTimeout(() => { fulfill('hello') }, 500)
})
// Promise<number>
var promisedNumber = new Promise(function (fulfill, reject) {
setTimeout(() => { fulfill(10) }, 1000)
});
// Promise<string>
var promisedString = new Promise(function (fulfill, reject) {
setTimeout(() => { fulfill('hello') }, 500)
})
// Promise<number>
var promisedNumber = new Promise(function asyncUnitOfWork(fulfill, reject) {
throw new Error('Could not produce number (throw)')
});
console.log('start')
promisedNumber.then(
function onFulfilled(value) {
// Promise<number>
var promisedNumber = new Promise(function asyncUnitOfWork(fulfill, reject) {
setTimeout(function () {
reject(new Error('Could not produce number'))
}, 1000)
});
console.log('start')
// Promise<number>
var promisedNumber = new Promise(function asyncUnitOfWork(fulfill, reject) {
setTimeout(function () {
fulfill(10)
}, 1000)
});
console.log('start')
promisedNumber.then(
// Promise<number>
var promisedNumber = new Promise(function asyncUnitOfWork(fulfill, reject) {
setTimeout(function () {
fulfill(10)
}, 1000)
});
console.log('start')
console.log('value: ', promisedNumber) // Promise {<pending>}
console.log('finish')
const { compose, curry } = require('lodash/fp')
// Success :: a -> Success a
const Success = value => ({
type: 'success',
value
})
Success.is = obj => obj.type === 'success'