[英]How to write with 2+ parameters function in point-free style
I'm trying to implement this pointful function 我正在尝试实现这个有意义的功能
const getItem = (items, id) => items.find(item => item.id === id);
in point-free style using ramda.js. 使用ramda.js以无点样式。
When i use something like this: 当我使用这样的东西时:
const getItem = find(propEq('id'));
the first parameter items
will be passed to find
function, but we will lose 2nd id
parameter. 第一个参数items
将被传递给find
函数,但是我们将丢失第二个id
参数。
The question is, how to implement getItem
function in point-free style? 问题是,如何在无点样式中实现getItem
函数?
If you are free to change the order of arguments of the function, useWith
is a simple solution: 如果您可以自由更改函数的参数顺序, 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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.