August 2018
Intermediate to advanced
380 pages
10h 2m
English
One solution that functional programming provides for the problem of dependency injection is that it can treat dependency requirement as a function defined with the dependency as an argument and then abstract this function away. If we want to do this, then first we have to define our database access methods as follows:
def createUserFunc (u: User ): Connection => Int = ???def createAccountFunc(a: Account): Connection => Int = ???
The approach states that whenever we have a computation that depends on some external resource, we model this dependency as a function that accepts this resource as an argument. So, when we have a method that is supposed to create a user, it does not perform the computation itself. Rather, it ...