Compose an arbitrary number of functions that accept one argument and return either a value or a Promise.
$ npm install promise-compose
import assert from 'assert'
import compose from 'promise-compose'
const double = x => x * 2
const square = x => x * x
const root = x => Promise.resolve(Math.sqrt(x))
// From left to right.
compose(root, double, square)(9)
.then(result => assert.equal(result, 36))
// From right to left.
compose.right(square, double, root)(9)
.then(result => assert.equal(result, 36))
This library assumes that Promise
is a global that implements the ES6 Promise specification. If you're not sure if the environment has Promise
or you want to use something else, simply override compose.Promise
.
This software is licensed under the MIT license.