Ramda ifElse 行为异常
Ramda ifElse behaving strangely
为什么当我 运行 这里的 ifElse
方法 false
记录 "function two (onTruthy)"?
var x = R.ifElse(R.T, function(){
console.log("function two (onTruthy)")
// console.log(arguments)
}, function(){
console.log("function three (onFalsy)")
// console.log(arguments)
})
x(false)
我认为这是因为 R.T 总是返回 true。也许使用 _.isMatch 我可以匹配它?
更新:刚试过:
var x = R.pipe(
R.partialRight(R.match, true),
R.partialRight(R.ifElse, function(){
console.log("function two (onTruthy)")
// console.log(arguments)
}, function(){
console.log("function three (onFalsy)")
// console.log(arguments)
})
)
R.T
对任何输入计算 true
。因此 R.ifElse(R.T, f, g)
可以简化为 f
.
在我看来,您正在寻找 R.ifElse(R.identity, f, g)
,但这可能更好地表达为 ... ? ... : ...
。
为什么当我 运行 这里的 ifElse
方法 false
记录 "function two (onTruthy)"?
var x = R.ifElse(R.T, function(){
console.log("function two (onTruthy)")
// console.log(arguments)
}, function(){
console.log("function three (onFalsy)")
// console.log(arguments)
})
x(false)
我认为这是因为 R.T 总是返回 true。也许使用 _.isMatch 我可以匹配它?
更新:刚试过:
var x = R.pipe(
R.partialRight(R.match, true),
R.partialRight(R.ifElse, function(){
console.log("function two (onTruthy)")
// console.log(arguments)
}, function(){
console.log("function three (onFalsy)")
// console.log(arguments)
})
)
R.T
对任何输入计算 true
。因此 R.ifElse(R.T, f, g)
可以简化为 f
.
在我看来,您正在寻找 R.ifElse(R.identity, f, g)
,但这可能更好地表达为 ... ? ... : ...
。