Search code examples
scalascalazzio

The difference between IO and UIO in scalaz ZIO


What is the difference between IO and UIO in the new version from ZIO for example UIO[Long] and IO[Nothing, Long]?


Solution

  • There is no difference. Type UIO[+A] = ZIO[Any, Nothing, A] and type IO[+E, +A] = ZIO[Any, E, A]. So both UIO[Long] and IO[Nothing, Long] are ZIO[Any, Nothing, Long] (i.e. any environment, no errors and value of Long).

    You could check this by verifying that

    implicitly[UIO[Long] =:= IO[Nothing, Long]]
    implicitly[IO[Nothing, Long] =:= UIO[Long]]
    

    compile.

    UIO[A] is IO[Nothing, A].