I currently have something like this implementation using Ramda's pipeP :
const fetchAmount = () => new Promise((resolve) => setTimeout(() => resolve({value: 5}, 1000)))
const getTotal = pipeP(
fetchAmount,
prop('value'),
add(2)
)
await getTotal() //=> 7
And I've seen that it's deprecated and the only solution I found is adding then
, like:
const fetchAmount = () => new Promise((resolve) => setTimeout(() => resolve({value: 5}, 1000)))
const getTotal = pipeP(
fetchAmount,
then(prop('value')),
then(add(2))
)
await getTotal() //=> 7
Is this the way to go? I guess there might be important reasons to deprecate pipeP
because it was really easy to use when combining promises with pure functions.
Yes, this was deprecated in v0.26.0 .
Ramda added pipeWith
and composeWith
, which covered a wider spectrum.
pipeP (f1, f2, ..., fn)
can be written as pipeWith (then) ([f1, f2, ..., fn])
.
If you want the exact same signature, you can write something like this:
const pipePromises = unapply (pipeWith (then)) pipePromises ( (n) => Promise .resolve (n + 1), (n) => Promise .resolve (n * n), (n) => Promise .resolve (n - 3) ) (4) .then (console .log) //~> 22
<script src="//cdnjs.cloudflare.com/ajax/libs/ramda/0.26.1/ramda.js"></script> <script>const {unapply, pipeWith, then} = R </script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.