I am implementing if/else statement, by using function "inCase" to make it more readable:
const size = 'small'
const equals = str1 => str2 => str2 === str1
const inCase = (obj) => (predicate) => (whenTrueFn) => (whenFalseFn) => {
predicate(obj) ? whenTrueFn() : whenFalseFn()
}
const renderMobileNavBar = () => console.log("Rendering Mobile")
const renderDesktopNavBar = () => console.log("Rendering Desktop")
const otherwise = fn => () => fn()
inCase(size)(equals('small'))(renderMobileNavBar)(otherwise(renderDesktopNavBar))
But in this case "otherwise" function is completely unnecessary I could have called my function like this:
inCase(size)(equals('small'))(renderMobileNavBar)(renderDesktopNavBar)
It works the same, the only difference is in readability. So I wonder does it make sense to keep "otherwise" function just for readability?
if
construct?