I am a dev trying to bend my mind around the typelevel stack (Cats and Cats-Effect)after years of experience with less functional scala.
I'm having a real trouble bending my head around the Reader monad. I can somewhat follow the examples here: https://dev.to/riccardo_cardin/and-monads-for-almost-all-the-reader-monad-1ife , but one point that totally baffles me (as a person from a more OO background) is WHY are we doing all this? It seems to me that in the end, we just end up with a bunch of functions of the type
def myMethod(arg1: A, arg2: B): Reader[MyContext, MyMethodReturnType]
def myMethod2(arg1: A): Reader[MyContext, SomeOtherReturnType]
Which to me sounds like the exact equivalent of the OO concept of a class:
class MyContext(/*class dependencies used by the methods*/) {
def myMethod(arg1: A, arg2: B): MyMethodReturnType
def myMethod2(arg1: A): SomeOtherReturnType
}
Quoting the article:
So, Stocks has a dependency upon StockRepository. How can we express such fact in the code? We don't want to use the constructor injection mechanism or anything related to it. We want to stay functional.
So, my question is why? The quote above seems to suggest that "staying functional" is its own reward, but can you give me an example that showcases how not using constructor injection is an advantage?
Thanks!