Divide and conquer has been a core strategy in software engineering. We decompose our systems into smaller modules with focused, simple functionalities and compose them back to provide richer features. In a complex modular system, developers regularly have to dedicate a significant portion of code and effort to such composition.
Needless to say, it provides major benefits to be able to compose and decompose computation with ease. This is where FP, i.e. Functional Programming mainly focuses on. For developers who wonder what difference FP makes, this blog post aims to give a taste of how it enables more natural composition. I am going to focus on one particular and yet common factor that makes computation composition cumbersome in imperative programming - effects.
Let's start with two functions with the return type of one matching the input type of the other. That is, given