p-compose
Like fp.compose, but for Promises.
p-compose
has been designed to function like fp.compose
.
This smally utility library exports a function that composes the given sync/async functions. The rightmost function can have any arity; the remaining have a fixed arity of 1.
Motivation
There's a number of modules out there for Promise function composition, but they have slight differences in expected behavior:
- Most of them don't support unlimited arity to the rightmost function.
- Most of them don't support non-native Promise libraries.
Usage
; const fetchUserById = { // Make some async db call or something... return Promise;}; const getUserFullNameById = ; ; // Prints 'Chuck Norris'
Browser Support
dist/p-compose.min.js
is UMD and can be imported using require/browsers.
Note: dist/p-compose.js
is the main export used by node/npm.
Using Non-Native Promises
You can use the static method using
to create a new compose
method
that will use the provided Promise library.
; // Creates a *new* function that will use bluebird promises.const compose = pcompose; const doSomething = ;const bluebirdPromise = ;