Using Ramda and a pointfree style, how can I copy the first element of an array to the end?

I want to take the array [1, 2, 3] and return [1, 2, 3, 1] .

I am using Ramda and I can get the desired result as follows:

 const fn = arr => R.append(R.prop(0, arr), arr); 

But I would like to do it for free. Here is the closest I got:

 const fn = R.compose(R.append, R.prop(0)); fn(arr)(arr) 

But it looks stupid. What am I missing? Thanks!

+1
javascript functional-programming
source share
2 answers

converge can be very useful for such things.

 const rotate = R.converge(R.append, [R.head, R.identity]) rotate([1, 2, 3]); //=> [1, 2, 3, 1] 
+2
source share

Component S is useful here:

 SS(SC(R.append), R.head, [1, 2, 3]); // => [1, 2, 3, 1] 
+1
source share

All Articles