Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pointfree version of a function using Ramda.js

I am trying to make the following function pointfree. I am not sure how I can pass the arguement to the inner function though. I am using Ramda.js, but I think the concept is more general than that. Here is the code I have.

search = function(id) {
  return find(propEq('id', id), items)
}

Here, you will notice that the id parameter is passed to the inner function propEq. That's the part I am unsure of.

like image 839
Nachiket Mehta Avatar asked Dec 11 '22 21:12

Nachiket Mehta


1 Answers

The question is more general than Ramda, but Ramda does have several functions to make things like this easier, especially useWith and converge.

This can be written points-free with useWith like this:

var search = useWith(find, propEq('id'), identity);
search(2, items); //=> {id:  2}

You can see it in action on the Ramda REPL.

like image 84
Scott Sauyet Avatar answered Dec 18 '22 08:12

Scott Sauyet