Injecting Dependencies
We have a number of low-level helper functions, such as toValidProductCode, that take a function parameter representing a service. These are quite deep in the design, so how do we get dependencies from the top level down to the functions that need them?
If we were doing object-oriented programming, we would use dependency injection, and possibly an IoC container. In functional programming, we don’t want to do that because the dependencies become implicit. Instead we always want to pass dependencies around as explicit parameters, which ensures that the dependencies are obvious.
There are a number of techniques for doing this kind of thing in functional programming, such as the “Reader Monad” and the “Free Monad,” but since ...
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.
Read now
Unlock full access