ramda: pipeP fails when first argument is function that does not return promise
This seems like obviously pathological behavior. Tested on version 0.18.0.
var R = require("ramda")
var Promise = require("bluebird")
var mulslow = R.curry(function (x, y) {
return new Promise(function (resolve, reject) {
resolve(x * y)
})
})
R.pipeP(mulslow(3))(3).then(console.log) // works
R.pipeP(mulslow(3),R.multiply(3))(3).then(console.log) // works
R.pipeP(mulslow(3),R.multiply(3),mulslow(3))(3).then(console.log) // works
R.pipeP(R.multiply(3), mulslow(3))(3).then(console.log).catch(console.log) // does not work.
R.pipeP(R.multiply(3))(3).then(console.log).catch(console.log) // does not work.
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 20 (12 by maintainers)
That function seems reasonable to me, @Zerim.
I think I’ve almost convinced @CrossEye that we should deprecate our Promise-specific functions, so I don’t expect
R.composeP
to be “fixed”.There are a few issues here:
pipeP
will return a Promise, meaning thatpipeP
as a whole won’t return a Promise which makes for inconsistent return types.Promise.resolve
on the output of the first function if it is missing athen
method, however this then adds a dependency on a Promise implementation.This can however be avoided currently by users starting the
pipeP
composition with the appropriate function from the Promise implementation that lifts plain values into a Promise instance. This is only necessary if the first function would otherwise not return a Promise.e.g. for ES6 Promises: