pogo : *r -> promise[r]
pogo(function*() {
yield sleep(1000)
const json = yield $.getJSON('/endpoint')
return json
// or: return yield $.getJSON('/endpoint')
}())
function lift(f) {
return function(...promises) {
return Promise.all(promises).then(values => f(...values))
}
}
// Simple, one-argument example
// getFirstName : user -> string
function getFirstName(user) {
return user.name.split(' ')[0]
}
// lift(getFirstName) : promise[user] -> promise[string]
const userPromise = $.getJSON('/users/1')
const firstNamePromise = lift(getFirstName)(userPromise)
// Multi-argument example
// add : ...num -> num
function add(...nums) {
return nums.reduce((sum, n) => sum + n)
}
// lift(add) : ...promise[num] -> promise[num]