如何使用Ramda编写无点函数JS？内容来源于 Stack Overflow，并遵循CC BY-SA 3.0许可协议进行翻译与使用

• 回答 (2)
• 关注 (0)
• 查看 (84)

```const myNumbers = [
{
top: 10,
bottom: 5,
rate: 5
},
{
top: 9,
bottom: 4,
rate: 3
},
];```

```const addTen = r.add(10);
const double = r.multiply(2);```

`const process = (top, bottom, rate) => r.multiply(r.subtract(bottom, top), rate)`

```muNymbers.map(({ top, bottom, rate }) =>
);```

2 个回答

```const { add, converge, evolve, map, multiply, pipe, prop, subtract } = R;

const myNumbers = [
{ top: 10, bottom: 5, rate: 5 },
{ top: 9, bottom: 4, rate: 3 },
];

const process = pipe(

evolve({
bottom: multiply(2),
}),

converge(multiply, [

converge(subtract, [
prop('bottom'),
prop('top'),
]),

prop('rate'),
]),
);

console.log(map(process, myNumbers));```
`<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.min.js"></script>`

```const process = ({top, bottom, rate}) => ((2 * bottom) - (10 + top)) * rate;

const myNumbers = [
{ top: 10, bottom: 5, rate: 5 },
{ top: 9, bottom: 4, rate: 3 },
];

console.log(R.map(process, myNumbers));```
`<script src="//cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.js"></script>`

​我建议你这样做。例如，

`converge(subtract, [prop('bottom'), prop('top')])`

`lift(subtract)(prop('bottom'), prop('top'))`