then-fold
v1.0.0
Published
Useful helper function for working with promises
Downloads
3
Readme
- then-fold
Really simple utility function for reducing a Promise returning function with an array of other functions.
#+BEGIN_SRC javascript npm install then-fold #+END_SRC
#+BEGIN_SRC javascript const thenFold = require('then-fold')
// function that returns a Promise function example (x) { return new Promise((resolve, reject) => { resolve(x) }) }
// transformation function function t1 (x) { return x + 1 }
// transformation function that returns a Promise function t2 (x) { return new Promise((resolve, reject) => { setTimeout(() => { resolve(x + 1) }, 200) })
thenFold(example(5), [ t1, t2 ]) // => 7 #+END_SRC
