rjhilgefort
12/4/2018 - 9:56 PM

pipeAny, composeAny

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"]