promised-pipe
A sweet composition of ramda.pipe and q.promised to make async pipes simple. No dependencies. Extremely lightweight.
Requirements
You only have to have Node 4+ or a ES5-compatible browser
Introduction
This library is extremely useful for those who use functions pipes (ramda.pipe, inverted underscore.compose, etc.), but struggle with composing both synchronous and asynchronous (Promise returning) functions in the same pipeline.
Install
Run:
npm i --save promised-pipe
Include:
const pipe = // or
Usage
It is a function with the same API as ramda.pipe
, except the created function will always return a Promise
const resultedFn = // => Promise
There is a bunch of tests in test.js which are quite readable
Examples
You can play and run all of these examples by npm i ramda && node example.js
(Node 6+ required).
Basic example with some simple math:
const inc = x + 1 // synchronous functionconst mul3 = x * 3 // synchronous functionconst div2promise = Promise // asynchronous function const mathFn = // 5 + 1 / 2 * 3 = 9
Numbers aren't so interesting! Example with fs:
const filePath = '/tmp/promised_pipe_example'// "Promisify" fs modulesconst readFile = fsconst writeFile = fs const fsFn = // HELLO
Still isn't sexy, right? Let's add some Ramda to the previous example:
const R = const readFileC = Rconst writeFileC = Rconst writeToTmp = const ramdaFsFn = // HELLO, RAMDA
So you can easily mix functions which return non-promises and functions which return promises.
It is highly recommended to use it with Ramda since it will make your experience a lot better.