[Ramda] Curry, Compose and Pipe examples

时间:2023-03-09 04:32:24
[Ramda] Curry, Compose and Pipe examples
const curry =  R.curry((fns, ary) => R.ap(fns, ary));
const applyMultiAndAdd = curry([R.multiply(), R.add()]);
const res = applyMultiAndAdd([,,]); console.log(res); //[2, 4, 6, 4, 5, 6] const compose = R.compose(
R.reverse,
R.ap([R.multiply(), R.add()])
);
const res1 = compose([,,]);
console.log(res1); //[6, 5, 4, 6, 4, 2] const addOne = R.curry( (x) => R.add(, x))
const pipe = R.pipe(
R.ap([R.multiply(), R.add()]),
R.reverse,
R.map(addOne)
); const res2 = pipe([,,]);
console.log(res2); //[7, 6, 5, 7, 5, 3]