ThomasReggi
ThomasReggi

Reputation: 59605

Ramda ifElse behaving strangely

Why when I run the ifElse method here does false log "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)

I'm thinking it's because R.T is always returning true. Perhaps using _.isMatch I can match it?

Update: Just tried:

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)
  })
)

Upvotes: 1

Views: 1151

Answers (1)

davidchambers
davidchambers

Reputation: 24876

R.T evaluates true for any input. Thus R.ifElse(R.T, f, g) can be simplified to f.

It appears to me that you're looking for R.ifElse(R.identity, f, g), but this could probably be better expressed via ... ? ... : ....

Upvotes: 3

Related Questions