Skip to content

Instantly share code, notes, and snippets.

@cqfd
Last active August 29, 2015 14:24
Show Gist options
  • Save cqfd/5028eda6b8e99f97646b to your computer and use it in GitHub Desktop.
Save cqfd/5028eda6b8e99f97646b to your computer and use it in GitHub Desktop.
Lifting promises.

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 as to promises for as.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment