Exit e-book
Show all chapters
05
The Has data type
05. 
The Has data type

Sign up to our Newsletter

Signing up to our newsletter allows you to read all our ebooks.

I agree to receive marketing communication from Scalac.
You can unsubscribe from these communications at any time. For more information on how to unsubscribe, view our Privacy Policy.

Mastering Modularity in ZIO with Zlayer
05

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.
PREVIOUS
Chapter
04
NEXT
Chapter
06