I am trying move more towards functional programming in my javascript applications. I currently use the library ramda as a base lib for this.
My desire:
- Create a function
findWithId(id, list)
which returns the item in the list with the property_id
matching the input id. - Make the implementation of it as short as possible, relying on existing code as much as possible.
Acheived so far:
My base is R.find
which has this defenition
find :: (a -> Boolean) -> [a] -> a | undefined
I tried some different solutions shown below:
//Using ramdajs (ramdajs.com)
var hasId = R.curry(function(id, item) {
return item._id === id
});
//This doesn't work
var findWithId_v1 = R.find(hasId);
//This works but can I make it as short as v1?
var findWithId_v2 = function(id, list) {
return R.find(hasId(id), list);
}
Question
Can I make findWithId_v2
as short as findWithId_v1
by using standard functional programming tools like compose, curry etc?