selfrefactor/rambda

compose question

lesar opened this issue · 2 comments

lesar commented

How many parameters can have the right most function?
work using more than one parameter?

const result = R.compose(
  R.map(x => x * 2),
  (a, y) => R.filter(x => x > y, a)
)([1, 2, 3, 4], 2)

// => []

Have I write a wrong example?

regards

lesar commented

change compose like this sound good?

function compose (...fns) {
  return (...args) => {
    const list = fns.slice()
    if (list.length > 0) {
      const fn = list.pop();
      let result = fn(...args);
      while (list.length > 0) {
        result = list.pop()(result)
      }
      return result
    }
    return undefined;
  }
}

regards

Thanks for opening this issue.

Seems like a very good suggestion, so it is implemented with the latest release of 1.1.0.