如何使用 Ramda 函数在索引处获取参数?

How can I take an argument at an index with Ramda functions?

备注

首先,我想post把这个发到代码审查网站;但是您至少需要 3 行代码,而这个问题不需要那么多代码。我知道这个问题对 SO 来说有点模糊,但我看不到一个更好的网站来 post 它。


实际问题

我发现它在一些情况下很有用,特别是在使用 ramda 时,能够拥有一个函数,该函数只传递给函数的 returns 参数 n

我能够生成的最简单方法是:

const takeArgument = argIndex => (...args) => args[argIndex];

这很好,可以满足我的需要,但我的问题是,有没有办法只使用 Ramda 函数来做到这一点?我找不到任何这样做的例子,但我觉得必须有一种简单的方法来做这样的事情。

正如@Thomas 在他的评论中提到的,这很容易通过 nthArg 实现,例如:

const { nthArg } = R;
const getSecondArg = nthArg(1)

const x = getSecondArg(1, 2)
console.dir(x)
<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.26.1/ramda.min.js"></script>