mercredi 22 février 2017

Translate Javascript if/else to Ramda cond issue

I found some problem on the handling after if/else logic checking. Let's take an example.

Basic config

const result = {
  data: 1,
  state: {
    pass: 'N'
  }
}

For JS if/else checking, the log should not show after logic checking

function checking() {
  if(result.state.pass !== 'Y') {
    return result;
  }

  console.log("Should not appear the log")
}

checking()

Then, I tried to translate it using Ramda cond function

function checking() {
  R.cond([
    [
      R.compose(R.not, R.equals('Y'), R.prop('pass'), R.prop('state')),
      () => result
    ]
  ])(result)

  console.log("Should not appear the log")
}

checking()

However, the log appear in Ramda cond example. May i know

  • is there anything wrong?

  • anything i can enhance on the example?

Thanks.

Aucun commentaire:

Enregistrer un commentaire