URIO[R, A] is a type alias for
ZIO[R, Nothing, A], which represents an effect that requires an
R, and cannot fail, but can succeed with an
In Scala, the type alias is a way to give a name to another type, to avoid having to repeat the original type again and again. It doesn't affect the type-checking process. It just helps us to have an expressive API design.
Let's see how the
URIO type alias is defined:
type URIO[-R, +A] = ZIO[R, Nothing, A]
URIO just equal to
ZIO which requires
R and cannot fail because in the Scala the
Nothing type has no inhabitant, we can't create an instance of type
Nothing. It succeeds with
In following example, the type of
URIO[Console, Unit] which means, it requires
Console service as an environment, and it succeeds with
def putStrLn(line: => String): ZIO[Console, IOException, Unit] =
ZIO.accessM(_.get putStrLn line)
Note: Principle of The Least Power
ZIOdata type is the most powerful effect in the ZIO library. It helps us to model various types of workflows. On other hand, the type aliases are a way of subtyping and specializing the
ZIOtype, specific for a less powerful workflow.
Lot of the time, we don't need such a piece of powerful machinery. So as a rule of thumb, whenever we require a less powerful effect, it's better to use the proper specialized type alias.
So there is no need to convert type aliases to the
ZIOdata type, whenever the
ZIOdata type is required, we can use the most precise type alias to fit our workflow requirement.