Functional Programming: Alternatives to the IF #Functional #JavaScript
▻https://hackernoon.com/functional-programming-alternatives-to-the-if-functional-javascript-8804
A couple of times I have been asked “How would you do X in functional programming?” I absolutely love these types of questions.I do my best to answer every question, but I think there are many questions interesting enough to warrant their own articles.So for this article I would like to demonstrate how I could recreate this imperative function in a more functional manner.This function has an if statement without an else. So while a ternary operator could work, it is not ideal.▻https://medium.com/media/29d9e7511c38ea379b141ea5967caa66/hrefHere we need to run dispatch
only when we have a value
, otherwise we do nothing.One option is to use a short circuit operator:▻https://medium.com/media/6c715f86b93a7d7c84c35e5a16814a00/hrefShort circuit and ternary and both ways you can solve this (...)