Idea: programming with a promise for an a
as if it were "more or less" an a
. That is, we don't want to have to change our programming style too much when transitioning from dealing with actual a
s to promises for a
s.
function lift(f) {
return function(...promises) {
return Promise.all(promises).then(values => f.apply(null, values))
}
}
lift
takes a function f
that operates on "regular" arguments. It promotes it to a function that operates on promised arguments, and it promises whatever f
would have done with them.