使用 Ramda 和 pointfree 样式,如何将数组的第一项复制到数组的末尾?
Using Ramda, and pointfree style, how can I copy the first item of an array to the end of it?
我想要一个数组 [1, 2, 3]
和 return [1, 2, 3, 1]
。
我正在使用 Ramda,我可以像这样得到想要的结果:
const fn = arr => R.append(R.prop(0, arr), arr);
但我想做到无分。这是我得到的最接近的:
const fn = R.compose(R.append, R.prop(0));
fn(arr)(arr)
但这看起来很傻。我错过了什么?谢谢!
converge
对此类事情很有帮助。
const rotate = R.converge(R.append, [R.head, R.identity])
rotate([1, 2, 3]); //=> [1, 2, 3, 1]
S combinator在这里很有用:
S.S(S.C(R.append), R.head, [1, 2, 3]);
// => [1, 2, 3, 1]
我想要一个数组 [1, 2, 3]
和 return [1, 2, 3, 1]
。
我正在使用 Ramda,我可以像这样得到想要的结果:
const fn = arr => R.append(R.prop(0, arr), arr);
但我想做到无分。这是我得到的最接近的:
const fn = R.compose(R.append, R.prop(0));
fn(arr)(arr)
但这看起来很傻。我错过了什么?谢谢!
converge
对此类事情很有帮助。
const rotate = R.converge(R.append, [R.head, R.identity])
rotate([1, 2, 3]); //=> [1, 2, 3, 1]
S combinator在这里很有用:
S.S(S.C(R.append), R.head, [1, 2, 3]);
// => [1, 2, 3, 1]