Skip to content

Instantly share code, notes, and snippets.

@rjhilgefort
Last active December 4, 2018 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rjhilgefort/f81ac1f0f8cb87fd18d3a609f7cbcf3a to your computer and use it in GitHub Desktop.
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
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