Last active
December 4, 2018 21:58
-
-
Save rjhilgefort/f81ac1f0f8cb87fd18d3a609f7cbcf3a to your computer and use it in GitHub Desktop.
`pipeAny` (`pipe` + `pipeP`) and `composeAny` (`compose` + `composeP`) allows sync and async functions mixed together in a pipeline. ramda repl: https://goo.gl/DD6jS5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.clear() | |
// util.js | |
///////////////////////////////////////////////////////////////// | |
const PromiseResolve = x => Promise.resolve(x) | |
// pipeAny.js | |
///////////////////////////////////////////////////////////////// | |
const pipeAny = compose( | |
apply(pipeP), | |
prepend(PromiseResolve), | |
unapply(identity), | |
); | |
// composeAny.js | |
///////////////////////////////////////////////////////////////// | |
const composeAny = compose( | |
apply(composeP), | |
append(PromiseResolve), | |
unapply(identity), | |
); | |
// app.js | |
///////////////////////////////////////////////////////////////// | |
const appendAsync = curry((x, y) => Promise.resolve(append(x, y))) | |
pipeAny( | |
append('one'), | |
appendAsync('two'), | |
prepend('surprise'), | |
appendAsync('four'), | |
adjust(0, toUpper), | |
)(['zero']) | |
.then((x) => console.log('pipeAny', x)) | |
// pipeAny | |
// ["SURPRISE","zero","one","two","four"] | |
composeAny( | |
append('one'), | |
appendAsync('two'), | |
prepend('surprise'), | |
appendAsync('four'), | |
adjust(0, toUpper), | |
)(['zero']) | |
.then((x) => console.log('composeAny', x)) | |
// composeAny | |
// ["surprise","ZERO","four","two","one"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment