在Ramda中以无点样式编写无参数函数?

Jon*_*nah 5 javascript functional-programming ramda.js

考虑下面的工作代码:

var randN = x => () => Math.floor(x*Math.random());
var rand10 = randN(10)
times(rand10, 10) // => [6, 3, 7, 0, 9, 1, 7, 2, 6, 0]
Run Code Online (Sandbox Code Playgroud)

randN是一个函数,它接受一个数字并返回一个RNG,当被调用时,它将返回[0,N-1]范围内的随机int.所以它是特定RNG的工厂.

我一直在使用ramda.js,学习函数式编程理论,我的问题是:是否可以randN使用ramda 重写一个免费的样式?

例如,我可以写:

var badAttempt = pipe(multiply(Math.random()), Math.floor)
Run Code Online (Sandbox Code Playgroud)

这将满足"无点样式"的要求,但不能表现得如下randN:调用badAttempt(10)只返回1到10之间的单个随机数,而不是在调用时生成1到10之间的随机数的函数.

我无法找到ramda函数的组合,使我能够以无点的方式进行重写.我不知道这是否只是我的失败,或者使用的一些特殊内容random,这会破坏参照透明度,因此可能与点自由风格不相容.

更新

在与Denys讨论后,我对解决方案略有不同:

randN = pipe(always, of, append(Math.random), useWith(pipe(multiply, Math.floor)), partial(__,[1,1]))
Run Code Online (Sandbox Code Playgroud)