Mastering Modularity in ZIO with Zlayer
The Has data type
As mentioned in the ZIO documentation page:
- Has[A] represents a dependency on a service A.
- Has[A] and a Has[B] can be combined horizontally with the ++ operator for obtaining a Has[A] with Has[B], representing a dependency on two services (if you are wondering what combined horizontally means, don’t worry too much because the idea will become clearer when we reimplement the Tic-Tac-Toe application).
- The true power of the Has data type is that it is backed by an heterogeneous map from service type to service implementation, so when you combine Has[A] with Has[B], you can easily get access to the A and B services implementations.
- We don’t usually need to create a Has directly, but we do that through ZLayer.