DEV Community

Discussion on: We don't need a ternary operator

 
joelnet profile image
JavaScript Joel

Yes you are correct. The expensiveGet method needs to take 2 arguments for it to work the way it is being called in ifElse.

I have created a working example that you can run.

const S = require('sanctuary')

const expensiveGet = (y) => {
  console.log("doing expensive get for", y)
  return 2
}
const condition = x => x === 100
const expensiveGetPlus = x => y =>
  expensiveGet(y) + x

S.ifElse (condition) (expensiveGetPlus (1))
  (expensiveGetPlus (-1)) (100)
//=> "doing expensive get for 100"

This example will show that ifElse only executes one of the functions.