Skip to Content
Mastering Functional Programming
book

Mastering Functional Programming

by Anatolii Kmetiuk
August 2018
Intermediate to advanced
380 pages
10h 2m
English
Packt Publishing
Content preview from Mastering Functional Programming

Functional solution

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning Functional Programming

Learning Functional Programming

Jack Widman

Publisher Resources

ISBN: 9781788620796Supplemental Content