Cofounded Host Collective (DiscountASP.net). Cofounded Player Axis (Social Gaming). Computer Scientist and Technology Evangelist with 20+ years of experience with JavaScript!
Cofounded Host Collective (DiscountASP.net). Cofounded Player Axis (Social Gaming). Computer Scientist and Technology Evangelist with 20+ years of experience with JavaScript!
Both expensive gets will run before the condition is even applied to true.
This is still false. Only one will run. Never both.
constisEven=n=>n%===0constlogEven=n=>console.log(`${n} is Even!`)constlogOdd=n=>console.log(`${n} is Odd`)ifElse(isEven)(logEven)(logOdd)(10)//=> "10 is Even!"
Cofounded Host Collective (DiscountASP.net). Cofounded Player Axis (Social Gaming). Computer Scientist and Technology Evangelist with 20+ years of experience with JavaScript!
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.
constS=require('sanctuary')constexpensiveGet=(y)=>{console.log("doing expensive get for",y)return2}constcondition=x=>x===100constexpensiveGetPlus=x=>y=>expensiveGet(y)+xS.ifElse(condition)(expensiveGetPlus(1))(expensiveGetPlus(-1))(100)//=> "doing expensive get for 100"
This example will show that ifElse only executes one of the functions.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
That's correct,
ifElse
accepts functions. So those functions are only executed when the condition is met.This is still false. Only one will run. Never both.
You can see
logOdd
is never called.In your first example
both run.
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.
This example will show that
ifElse
only executes one of the functions.