Skip to content

Instantly share code, notes, and snippets.

@robinpokorny
Created January 4, 2017 10:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robinpokorny/e4587c6cf6faf05d06da958e8cce2320 to your computer and use it in GitHub Desktop.
Save robinpokorny/e4587c6cf6faf05d06da958e8cce2320 to your computer and use it in GitHub Desktop.
Promise sequence fallback (first non-empty)
export default (tasks, {
args = [],
initial,
isEmpty = (x) => !x
} = {}) =>
tasks.reduce(
(prev, next) => prev.then((value) =>
isEmpty(value) ? next(...args) : value
),
Promise.resolve(initial)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment