Error and Dependency Channels
Typed errors and env.
Two Powerful Channels
Beyond the success value, ZIO[R, E, A] tracks a typed error channel E and a dependency channel R. Both are visible in the type, making failures and requirements explicit at compile time.
Typed Errors
Model domain failures as a sealed hierarchy and put it in E. The compiler then forces you to handle exactly those cases.
import zio._
sealed trait AppError
case object NotFound extends AppError
case object Forbidden extends AppError
val lookup: IO[AppError, String] = ZIO.fail(NotFound)All lessons in this course
- The ZIO Effect
- Composing ZIO
- Error and Dependency Channels
- Running ZIO Apps