Skip to content

ZIO Type Aliases

With its three type parameters, ZIO is extremely powerful. We can use the environment type parameter to propagate information downward in our program (databases, connection pools, configuration, and much more), and we can use the error and success type parameters to propagate information upward.

In the most general possible case, programs need to propagate dependencies down and return results up, and ZIO provides all of this in a type-safe package.

But sometimes, we may not need all of this power. We may know that an application doesn’t require an external environment, or that it can only fail with a certain type of errors, or that it can’t fail at all.

To simplify these cases, ZIO comes with a number of useful type aliases. You never have to use these type aliases if you don’t want to. You can always just use the full ZIO type-signature. However, these type aliases are frequently used in ZIO code bases, so it is helpful to be familiar with them, and they can make your code more readable if you choose to use them.

The key type aliases are:

type IO[+E, +A] = ZIO[Any, E, A]
type Task[+A] = ZIO[Any, Throwable, A]
type RIO[-R, +A] = ZIO[R, Throwable, A]
type UIO[+A] = ZIO[Any, Nothing, A]
type URIO[-R, +A] = ZIO[R, Nothing, A]

Here is a brief description of each type alias to help you remember what they are for:

  • IO[E, A] - An effect that does not require any environment, may fail with an E, or may succeed with an A.
  • Task - An effect that does not require any environment, may fail with a Throwable, or may succeed with an A.
  • RIO - An effect that requires an environment of type R, may fail with a Throwable, or may succeed with an A.
  • UIO - An effect that does not require any environment, cannot fail, and succeeds with an A.
  • URIO[R, A] - An effect that requires an environment of type R, cannot fail, and may succeed with an A.

Several other data types in ZIO and other libraries in the ZIO ecosystem use similar type aliases, so if you are familiar with these, you will be able to pick those up quickly, as well.