简体   繁体   中英

How to write this point-free?

Can I write this somehow using ramda?

const getJobs = data => anotherF('/jobs', data)

perhaps something like

const getJobs = anotherF('/jobs', nthArg(0))

Thank you

If anotherF is already a curried function, then you can just write

const getJobs = anotherF('/jobs')

So, if it's not curried, or if you don't know, you can write

const getJobs = curry(anotherF)('/jobs')

But there is a good reason to wonder why it would be worth it. I'm one of the founders of Ramda and I'm a big fan, but I think of it as a toolkit to use when it makes my code easier to read and write. Any other use seems a misuse.

You can use R.partial to apply /jobs' to the function, and return a new function that expects the data :

 const anotherF = (path, data) => console.log(path, data) const getJobs = R.partial(anotherF, ['/jobs']) getJobs('data') 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.26.1/ramda.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