如何以无点样式编写带有 2+ 个参数的函数

How to write with 2+ parameters function in point-free style

我正在尝试实现这个有意义的功能

const getItem = (items, id) => items.find(item => item.id === id);

使用 ramda.js 的无点样式。

当我使用这样的东西时:

const getItem = find(propEq('id'));

第一个参数 items 将传递给 find 函数,但我们将丢失第二个 id 参数。

问题是,如何实现getItem无点风格的功能?

如果您可以随意更改函数参数的顺序,useWith 是一个简单的解决方案:

const getItemById = R.useWith(
  R.find,
  [R.propEq('id')]
);

console.log(
  getItemById(
    'b',
    [{ id: 'a' }, { id: 'b' }]
  )
);
<script src="//cdnjs.cloudflare.com/ajax/libs/ramda/0.24.0/ramda.min.js"></script>