Search code examples
functional-programmingramda.jspointfree

How to make an if statement point free


I have the following if statement:

var formatCity = 
    obj => R.both(has('city'), has('state'))(obj) ? appendCommaToCity(obj) : obj

I would like to make this code point free, but can not figure out a way around the if statement.


Solution

  • That's quite simple actually using the ifElse function - or its specialisation, when:

    const formatCity = R.when(R.both(has('city'), has('state')), appendCommaToCity);