Functional Programming

Functional programming is the future. It has a lot of restrictions. More rules than usual. But following those rules make the program easy to read, easy to write and make it less error probe. Some of the rules are like you can’t access variables from outside the function. Your function must be pure basically. Pure functions have this rule. For given input it should always return the same output. That means the result of the function should depend only on the arguments passed. It can’t read outside variables. It can’t make IO. No IO. Functions can’t have IO. That is the trickiest part. Every program needs IO. What we do it push IO related code to the side and try to write pure functions as much as we can. But it is impossoble. There are tricks to make it happen. Those are things that are hard to learn. Monads. We call them. They are famous words. You hear them all the time. They are hard to learn. People say that to scare you. The promises in JavaScript are kind of monads. If you know promises in JavaScript. If you UNDERSTAND promises in JavaScript, you can find a bit of resemblance. There are a lot of monads. IO monad, future monad, list is also a monad. Option monad is cool. You will love it when you use it. Saves a lot of ugly code. Yes you won’t write a lot of ugly code here. You won’t have to use nested ifs. You don’t update any variables in a program. It is like building pipelines. You write functions after functions.