簡體   English   中英

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)

我在想這是因為RT總是回歸真實。 也許使用_.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)
  })
)

RT評估任何輸入的true 因此, R.ifElse(RT, f, g)可以簡化為f

在我看來,你正在尋找R.ifElse(R.identity, f, g) ,但這可能更好地通過... ? ... : ...來表達... ? ... : ... ... ? ... : ...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM