How can I make the following function pointfree (using Ramda)?
const prefixAll = R.curry((prefix, list) => R.map(R.concat(prefix), list))
Also, this should work
R.useWith(R.map, [R.concat, R.identity])
(
R.identityis there for proper arity of the function, see @scott-sauyet's comment.)
P.S: But I personally think, that compose is better – using partial application of argument is more functional approach. e.g. R.compose(R.map, R.concat)('a')(['a','b'])
prefixAll = R.useWith(R.map, [R.concat, R.identity]). This has the same behavior as above, but this function will properly report its arity.identity simply says that there is a second parameter, but it is not modified before being passed into map. R.useWith(R.map, [R.concat]).length; //=> 1, but R.useWith(R.map, [R.concat, R.identity]).length; //=> 2. I find it a matter of being a good citizen to have my functions properly report their arities (the number of parameters they accept.) Of course Ramda's currying muddies the water since it allows you to use these functions with varying arities, but I think the full number of parameters is the correct behavior.I entered the code into pointfree.io (well I first converted it to Haskell \prefix list -> map (prefix ++) list), and it returned:
map . (++)
So the JavaScript equivalent should be:
const prefixAll = R.compose(R.map, R.concat);
When I test this in the ramda's REPL I think I obtain the desired result.
compose are passed to the first function, but in this case the second argument needs to be passed to the result of the composition. useWith seems to be the right tool for this job.IMO the simplest way is using comprehensions which are achieved in this case with R.lift lifting the R.concat function.
const prefixAll = R.lift(R.concat);
prefixAll(['hi-'], ['you', 'there']); // => ["hi-you", "hi-there"]
Note that the prefix must be passed as a single-element array. This function is automatically curried by Ramda for you.
R.xprod(["a"], ["b", "c", "d"])returns[["a", "b"], ["a", "c"], ["a", "d"]]