[Ramda] Curry, Compose and Pipe examples

发布时间:2016-12-31 7:34:50
来源:分享查询网

const curry =  R.curry((fns, ary) => R.ap(fns, ary));
const applyMultiAndAdd = curry([R.multiply(2), R.add(3)]);
const res = applyMultiAndAdd([1,2,3]);

console.log(res); //[2, 4, 6, 4, 5, 6]


const compose = R.compose(
  R.reverse,
  R.ap([R.multiply(2), R.add(3)])
);
const res1 = compose([1,2,3]);
console.log(res1); //[6, 5, 4, 6, 4, 2]

const addOne = R.curry( (x) => R.add(1, x))
const pipe = R.pipe(
  R.ap([R.multiply(2), R.add(3)]),
  R.reverse,
  R.map(addOne)
);

const res2 = pipe([1,2,3]);
console.log(res2); //[7, 6, 5, 7, 5, 3]

返回顶部
查看电脑版