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 ...
Get Domain Modeling Made Functional now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.