简体   繁体   中英

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.

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.

The question is, how to implement getItem function in point-free style?

If you are free to change the order of arguments of the function, useWith is a simple solution:

 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> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM