My goal is to create a custom map function that first needs to filter the list to remain, for example, only even items before invoking the supplied function on every item. I do need the function to be curried and for the first parameter to be the function, not the list. I believe the signature would look like this: (a -> b) -> [a] -> [b]
There are of course many ways to do this. Here is what my first attempt looked like.
var isEven = x => x % 2 === 0;
var filterEvensMap = R.curry((fn, items) => R.map(fn, R.filter(isEven, items)));
filterEvensMap(R.negate, [1,2,3,4]); // [-2, -4]
However, since the above uses an anonymous function with the fn
and items
"glue parameters", I'm not sure this is the way that Ramda was intended to be used.
Below I included another way to do it. It seems to be more in the spirit of Ramda but I'm not sure if I'm over complicating things.
var filterEvensMap = R.compose(
R.flip,
R.uncurryN(2)
)(R.compose(
R.flip(R.map),
R.filter(isEven)
));
Am I overcomplicating with the multiple composes and uncurryN? Is there a more idiomatic way to achieve this? In your experience, does it matter?
Thanks in advance.